🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

import function with user-defined class!

Started by
4 comments, last by loboWu 16 years, 5 months ago
In AS 2.11.1, I found a bug about import function with user-defined class. engine->BindAllImportedFunctions() return no error. But when I execute, the import function will cause unbound function error! Here is the simple testing program: //file i.h , this is the user-defined class #ifndef _I_H #define _I_H class MyStruct { uint8 index; string name; string des; }; #endif //file i.as #include "i.h" MyStruct st; void GetStruct(MyStruct &out v) { st.name="test"; v = st; } MyStruct@ GetStructHandle() { st.name="test2"; return @st; } //file main.as #include "i.h" import void GetStruct(MyStruct &out) from "LIB"; import MyStruct@ GetStructHandle() from "LIB"; void main() { MyStruct v; MyStruct @handle; GetStruct(v); <-------- cause "Unbound function call exception" @handle = @GetStructHandle();<-------- cause "Unbound function call exception" }
Advertisement
I try to use any object as container,
and it doesn't assert exception,
but the members of MyStruct is alway empty.

Maybe the script-defined class couldn't cross-module ?
after reference the test_structintf,
I use a global any object to save the script-defined class,
and it works now!

Now I realize that, local any object couldn't cross-module(neither by-reference nor by value), and the script-defined class couldn't used as parameter of import function.
I'll have to look into this. The code should have returned an error when you tried to bind a function with script declared classes.

In a future version I'll also improve the code so that at least functions that take parameters with interface handles can be imported (if the interface has been declared exactly the same way in both modules).

Making script classes 'cross-module' is more difficult, since they can be affected by such things as position of global variables etc. But I'll try to allow even classes to be accepted 'cross-module'. It will however be a while before I can make this work, since it requires quite a lot of changes to the code.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I tried to reproduce the problem you explained about BindAllImportedFunctions() but couldn't. The BindAllImportedFunctions() returns an error as expected in this situation. The return code is -19 (= asCANT_BIND_ALL_FUNCTIONS).

Perhaps you were expecting a message in the message callback and forgot to check the return code?

Here's the test I made
static const char *script3 ="class A                                         \n""{                                               \n""  int a;                                        \n""}                                               \n""import void Func(A&out) from \"DynamicModule\"; \n""import A@ Func2() from \"DynamicModule\";       \n";static const char *script4 = "class A                   \n""{                         \n""  int a;                  \n""}                         \n""void Func(A&out) {}       \n""A@ Func2() {return null;} \n";bool Test(){	bool fail = false;	int number = 0;	int r;	asIScriptEngine *engine = 0;	COutStream out;	// Test 2	// Two identical structures declared in different modules are not the same	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);	RegisterScriptString_Generic(engine);	engine->AddScriptSection(0, TESTNAME ":3", script3, strlen(script3), 0);	r = engine->Build(0); assert( r >= 0 );	engine->AddScriptSection("DynamicModule", TESTNAME ":4", script4, strlen(script4), 0);	r = engine->Build("DynamicModule"); assert( r >= 0 );	// Bind all functions that the module imports	r = engine->BindAllImportedFunctions(0); assert( r < 0 );	engine->Release();	// Success	return fail;}

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

yes! it's my fault.
I didn't check the return code.
Thank you very much.

This topic is closed to new replies.

Advertisement