Sign in to follow this  

Class, interface

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

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!

Share this post


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

Share this post


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

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.


Share this post


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

Share this post


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

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

Share this post


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


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

Share this post


Link to post
Share on other sites

This topic is 3292 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this