RTTI property not found for CPP targets in Haxe NME - c++

I'm using rtti in haxe nme. It works well when targeting flash but when compiling to a cpp target I receive the following error.
error C2039: '__rtti' : is not a member of 'Class_obj'
I'm doing this...
public function doSomething(type:Class<Dynamic>):Void {
var typeInfo:String = untyped type.__rtti;
}
I also tried...
public function doSomething <T:Infos> (type:Class<T>):Void {
var typeInfo:String = untyped type.__rtti;
}
What should I do?

Make it looser! :Dynamic instead of :Class<Dynamic>
public function doSomething(type:Dynamic):Void {
var typeInfo:String = untyped type.__rtti;
}

Related

UActorComponent derived class in plugin is not reacting for function calls

So I have a little problem with creating project plugin in Unreal Engine for (4.15). So let's break it down.
1.I've created MyClass that is derived from UActor Component and has also this line:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
2.I've added that component to my GameMode.
3.Then I'm trying to call any function from inside the class by Get GameMode then casting to MyGameMode and getting MyClassComponent.
4.When I'm trying to call function nothing happens at all.
I was trying to debug it but it never goes in function body but prints before function and after works perfectly fine. I also must say that when functions are compiled straight into project they work 100% fine!
This is sample of how do I declare my functions:
UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
void TestFunction();
void UMyClass::TestFunction()
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "hello there");
}
If there is any more information required that I'm not aware of please let me know.
MyClass declaration
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class UMyClass : public UActorComponent
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
void TestFunction();
};
Any classes that need to be consumed publicly need to have their symbols exported.
In UE plugins this is achieved with the YOURPLUGIN_API specifier, where YOURPLUGIN is the name of the plugin.
This in turn is defined as __declspec(dllexport) when exporting and __declspec(dllimport) when consuming the plugin.
So your class definition should look like:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYPLUGIN_API UMyClass : public UActorComponent
{
...
}

How to access files in iOS project inside C++ function?

So I call my C++ function through my OpenCVWrapper. In this function I have to open a file which is located in my Xcode project. Is it possible to specify the desired path in C++ function?
Or I have to pass a file through the OpenCVWrapper in Swift?
In short, it looks smth like:
func sample() {
OpenCVWrapper.booProcess()
}
in OpenCVWrapper.mm
#implementation OpenCVWrapper : NSObject
+ (void)booProcess {
boo();
}
- (void)boo:
{
return boo();
}
#end
blink.cpp
void boo()
{
cv::CascadeClassifier my_cascade;
my_cascade.load("bar.xml");
}
All necessary wrappers have been added.
enter image description here
I didn't find any proper way to get a file path in C++ function. So the most obvious solution is getting a String representation of the path in Swift.
let path = NSBundle.mainBundle().pathForResource("bar", ofType:"xml")
Then pass it through the wrapper to C++ function
OpenCVWrapper.booProcess(path)
In your OpenCVWrapper.mm you have to convert a NSString into a std::string like
std::string *mypath = new std::string([path UTF8String]);
Then you may pass this path to C++ function through the wrapper.
+ (void)booProcess:(NSString*)path {
std::string *mypath = new std::string([path UTF8String]);
boo(*mypath);
}
Unfortunately it is not currently possible to call C++ code from Swift. You will have to wrap OpenCVWrapper in Objective-C, and then call it in Swift.
See Using Swift with Objective-C for more info.

TextureCache::addImageAsync selector typecast issue

I'm trying to use addImageAsync for the first time, but i cannot get the syntax working. I'm using Cocos2dx 3.3 final and Xcode 6.1.1.
My code is as follows :
(GFXManager.h)
#include "cocos2d.h"
class GFXManager
{
...
void loadStuff();
void textureLoaded(Ref* pObj);
}
(GFXManager.cpp)
...
void GFXManager::loadStuff()
{
std::string path = "whatever.png";
Director::getInstance()->getTextureCache()->addImageAsync(path, callfuncO_selector(GFXManager::textureLoaded));
}
void GFXManager::textureLoaded(Ref* pObj)
{
...
}
The above is based on the "Texture2dTest" sample from Cocos2dx.
But at the line with the addImageAsync instruction Xcode keeps saying this:
Static_cast from 'void (GFXManager::*)(cocos2d::Ref * )' to 'cocos2d::SEL_CallFuncO' (aka 'void (cocos2d::Ref::*)(cocos2d::Ref *)') is not allowed
I tried making 'GFXManager' a class derived from 'Layer' (as in Texture2dTest), and using 'CCObject' in place of 'Ref' (as in Texture2dTest...But 'CCObject' is deprecated and now it is called 'Ref'), with no luck.
But every example i've found on the web about using addImageAsync calls the selector with that syntax.
So what am i doing wrong ?
You need to change callfuncO_selector with std::bind or CC_CALLBACK_1:
void GFXManager::loadStuff()
{
std::string path = "whatever.png";
Director::getInstance()->getTextureCache()->addImageAsync(path, CC_CALLBACK_1(GFXManager::textureLoaded, this));
}
because TextureCache::addImageAsync accepts std::function not the function pointer

Is casting necessary in Typescript for this simple case?

Say I have a test.ts and a MY_MODULE.d.ts file:
MY_MODULE.d.ts:
module MY_MODULE
{
export class Config {
UserId : string;
};
export function Init( config : Config );
}
test.ts:
/// <reference path="MY_MODULE.d.ts" />
MY_MODULE.Init(<MY_MODULE.Config>{ UserId: 'Josh' });
My question: Is it possible to fix either the definition file or the .ts file so that the cast in the latter is unnecessary?
Use export interface Config instead of export class Config.
Typescript will infer the correct type based on the signature of the object, so the cast is not necessary.
Copying the code into the playground, a couple of compile errors were immediately picked up. Firstly, Init needs an implementation.
Secondly, the Config class does not have a constructor.
The following code compiles cleanly:
module MY_MODULE
{
export class Config {
UserId : string;
};
export function Init( config : Config ) {
}
}
var myConfig = new MY_MODULE.Config();
myConfig.UserId = 'Josh'
MY_MODULE.Init(myConfig);
It would be better to define a constructor for Config as follows:
module MY_MODULE
{
export class Config {
UserId : string;
constructor(userId : string) {
this.UserId = userId;
}
};
export function Init( config : Config ) {
}
}
MY_MODULE.Init(new MY_MODULE.Config('Josh'));

How to implement an interface in managed c++?

Here's interface that I have declared:
[ServiceContract]
public interface class IShedluer
{
[OperationContract]
array<Object^>^ GetResult(UInt64 taskId);
}
Here's the class that is trying to implement it:
ref class MyShedluer:IShedluer
{
Shedluer ^shedluer;//this is NOT MyShedluer
public:
MyShedluer(void);
array<Object^>^ GetResult(UInt64 taskId)
{
return shedluer->GetResult(taskId);
}
}
When I'm trying to compile this, I'm getting
Error 15 error C3766: 'MyShedluer' must provide an implementation for
the interface method 'cli::array<Type> ^IShedluer::GetResult(unsigned __int64)'
d:\users\menkaur\documents\visual studio 2010\projects\MyProject\
\kernel\MyShedluer.h 78 1 MyProject.Kernel
Why am I getting this?
the correct syntax for implementing an interface is to add virtual:
ref class MyShedluer:IShedluer
{
public:
virtual array<Object^>^ GetResult(UInt64 taskId);
}
Also the compiler tells you this, look at your warnings as well:
warning C4488: 'MyShedluer::GetResult' : requires 'virtual' keyword
to implement the interface method 'IShedluer::GetResult'