Class, interface
HI Angel,
My question is this:
I know u can register the Interface, class into script engine.
I know you can create the class and interface in the script code inside of script engine.
My question is:
Can I combine them togather?
What I mean is this:
I register a Interface, and in the angel code, I addScriptSection, which have a class inherit from registered Interface, can I do that?
What about to inherit from another class?
example:
class a{};
class b : a {};
Cheers!
Script classes can implement interfaces, whether the interface was registered by the application or declared in the script itself. The application would register the interface if it needs to a specific way of communicating with the script classes.
Inheritance between script classes is not yet available in AngelScript, but I'm getting closer to implementing it every day. Perhaps in early 2009.
Inheritance between script classes is not yet available in AngelScript, but I'm getting closer to implementing it every day. Perhaps in early 2009.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Cool.
Is that mean when I register a interface IntA in the script, I created a script class ChildA, which is inherit from IntA, then I pass the ref of ChildA to the application, application can orgnaise it as IntA? In another words, it refers to the Code inside of Script class ChildA in the application?
what I want to see here is that: the application can call the class (script class) method which is created in the script.
Is that possible?
What did u do on the build stage? produce assembly code? binary code? or something else?
If this is possible, I believe the AngelScript is really powerful, since it can extend the funtionalities of a application. And it is very easy to communicate with the applicaiton other than Python, Luna, and so on.
:).
Cheers
Is that mean when I register a interface IntA in the script, I created a script class ChildA, which is inherit from IntA, then I pass the ref of ChildA to the application, application can orgnaise it as IntA? In another words, it refers to the Code inside of Script class ChildA in the application?
what I want to see here is that: the application can call the class (script class) method which is created in the script.
Is that possible?
What did u do on the build stage? produce assembly code? binary code? or something else?
If this is possible, I believe the AngelScript is really powerful, since it can extend the funtionalities of a application. And it is very easy to communicate with the applicaiton other than Python, Luna, and so on.
:).
Cheers
Quote: Original post by WitchLord
Script classes can implement interfaces, whether the interface was registered by the application or declared in the script itself. The application would register the interface if it needs to a specific way of communicating with the script classes.
Inheritance between script classes is not yet available in AngelScript, but I'm getting closer to implementing it every day. Perhaps in early 2009.
Yes, the application can call the methods of a script class. The same way it can call the global script functions. The script class doesn't have to implement an interface for the application to call the methods, as the application can enumerate the methods of the script class and find the one it wants anyway.
AngelScript compiles the script code into bytecode, which is then interpreted by a virtual machine.
Regards,
Andreas
AngelScript compiles the script code into bytecode, which is then interpreted by a virtual machine.
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
R you saying that the application using script engine methods to call the script class method?
Let me give u a simple example:
In Application:
In the script engine:
The class C is script class.
now, we have one global variable in the application: A *aaa;
we register this global variable inside of script.
do following code in the script
Is this the same as what you explained above?
Let me give u a simple example:
In Application:
Class A {public:bool handle() = 0;};Class B: A {public:bool handle() { printf("Application handle\n"); return true; }};
In the script engine:
// register class A as interface.//......class C: A {bool handle() { print("Script methods\n"); return true; }}
The class C is script class.
now, we have one global variable in the application: A *aaa;
we register this global variable inside of script.
do following code in the script
// init the aaa, which is called a script method to give a instance class C.initAAA();// expect output: Script methods.aaa->handle();
Is this the same as what you explained above?
Quote: Original post by WitchLord
Yes, the application can call the methods of a script class. The same way it can call the global script functions. The script class doesn't have to implement an interface for the application to call the methods, as the application can enumerate the methods of the script class and find the one it wants anyway.
AngelScript compiles the script code into bytecode, which is then interpreted by a virtual machine.
Regards,
Andreas
No, script classes can't inherit from C++ abstract classes (a.k.a. interfaces). I don't know if it will ever be possible to do that, probably not.
Script classes can only implement script interfaces, which can be registered with RegisterInterface(), or can be declared in the scripts with 'interface MyIntf {}'.
You can however, implement a proxy class that can inherit your C++ abstract class, and then call script class methods to execute the implementation of each interface method. That way you'll be able to use scripts to extend your classes, without the rest of the application knowing that it is really scripts that are executed.
Example:
Regards,
Andreas
Script classes can only implement script interfaces, which can be registered with RegisterInterface(), or can be declared in the scripts with 'interface MyIntf {}'.
You can however, implement a proxy class that can inherit your C++ abstract class, and then call script class methods to execute the implementation of each interface method. That way you'll be able to use scripts to extend your classes, without the rest of the application knowing that it is really scripts that are executed.
Example:
class IEntity{public: virtual void OnFrame() = 0;};class CScriptProxy : public IEntity{public: CScriptProxy(int typeId) { scriptObj = (asIScriptStruct*)engine->CreateScriptObject(typeId); } ~CScriptProxy() { if( scriptObj ) scriptObj->Release(); } void OnFrame() { asIScriptContext *ctx = engine->CreateContext(); ctx->Prepare(scriptObj->GetObjectType()->GetMethodIdByDecl("void OnFrame()")); ctx->SetObject(scriptObj); ctx->Execute(); ctx->Release(); }protected: asIScriptStruct *scriptObj;};
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement