hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

cppia: add scripting support code only for selected classes

Open romamik opened this issue 1 year ago • 1 comments

When compiling haxe code with the '-D scriptable' option, the compiler adds additional C++ code to provide support for scripting. However, this code does not compile when the original Haxe code interacts with native C++ types.

class Main {
	static function main() {
		trace('Hello from cppia HOST');
		var scriptname = './script.cppia';
		cpp.cppia.Host.runFile(scriptname);
	}

	// the problem is here: I'm using cpp type `void*`
	static function cppTest(param: cpp.Star<cpp.Void>): Void {
		trace(param);
	}
}

Cpp compiler error and corresponding code:

./src/Main.cpp:108:19: error: no viable conversion from 'Dynamic' to 'void *'

static void CPPIA_CALL __s_cppTest(::hx::CppiaCtx *ctx) {
    Main_obj::cppTest(ctx->getObject(sizeof(void*)));
}

Here, ctx->getObject() returns Dynamic, but cppTest expects void*.

I do not need this function to be available for cppia scripts, as there is a limited set of classes and functions that should be available. Is it possible to generate the scripting support code only for selected classes and functions?

This is a duplicate of https://community.haxe.org/t/cppia-do-not-add-scripting-support-to-some-classes/3933

romamik avatar Apr 21 '23 08:04 romamik