Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

use existing class instance?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Zich   Members   -  Reputation: 122

Like
0Likes
Like

Posted 30 November 2004 - 06:11 AM

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.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3291

Like
0Likes
Like

Posted 30 November 2004 - 06:59 AM

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);
}

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS