hxcpp
hxcpp copied to clipboard
Cppia compile fails when declaring a variable of type cpp.cppia.Module in class
Found a weird issue when using cppia. The following Haxe code for a Cppia host fails during the C++ compilation step:
import cpp.cppia.Module;
class Host {
public static var myLoadedModule:Module = null;
public static function main(){
var src = sys.io.File.getContent('./script.cppia');
myLoadedModule = Module.fromString(src);
myLoadedModule.boot();
myLoadedModule.run();
}
}
The error I get is this:
... Error: boot.cpp include\Host.h(55): error C2039: 'CppiaLoadedModule': is not a member of 'hx' ...
The error can be avoided by removing the myLoadedModule
declaration from the class, and declaring it in the scope of main:
import cpp.cppia.Module;
class Host {
//public static var myLoadedModule:Module = null;
public static function main(){
var src = sys.io.File.getContent('./script.cppia');
var myLoadedModule = Module.fromString(src);
myLoadedModule.boot();
myLoadedModule.run();
}
}
The error also happens if myLoadedModule
is declared non-static.
I tested it on Windows 10 and Ubuntu using haxe version 3.4.4 and hxcpp versions 4.0.8 and 4.0.19
Here is the HXML file I used to build it:
-cp src/host
-main Host.hx
-D scriptable
-cpp out
Also, a workaround is to declare the member variable as Dynamic
Yeah, it is defined as an external class - I will need to do a little work to make this cppia safe. Dynamic seems like a good work-around. You could even make it Dynamic on cppia only, and Module on cpp.