Jump to content
  • Advertisement
Sign in to follow this  
loboWu

import function with user-defined class!

This topic is 3928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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" }

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!