Jump to content
  • Advertisement
Sign in to follow this  
Zich

use existing class instance?

This topic is 4979 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

Got another for you... is there a way to have angelscript use a method within an existing class instance for a function call from angelscript, instead of creating a new instance? i.e.: // c++ class MyClass { public: void myMethod() {} }; MyClass myInstance; // angelscript whateverFunction(); ^^^ myInstance.myMethod() gets called here? I'm working on a somewhat unusual project where I absolutely have to use the existing instance.

Share this post


Link to post
Share on other sites
Advertisement
If the script is calling a global function there is no way AngelScript can make it a class method as it has no knowledge of the object instance. However you have a couple of options for solving your problem.

1. You can register the class method as an object method, and then register the instance as a global property. That way the script would be able to call the method on the globally available object.


// AngelScript
void ScriptFunction()
{
// obj is a globally available variable registered by the application
obj.Function(12, 34);
}



2. You can also write a wrapper function for the class method. The wrapper function would then get the object instance and call the class method:


// C++ wrapper function
int Function(int a, int b)
{
Obj *obj = GetObjectInstance();
return obj->Function(a, b);
}

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!