Sign in to follow this  
_Sigma

Question on methods...

Recommended Posts

I think I know the answer to this but I'll ask anyways: Can I register a class's method (non static) with AS without creating a wrapper and without registering the class with AS? I assume this can't be done. The main heart of my game is the kernel (an instance of TKernel). I want to be able to call some of it's members from within the script (ie: Kernel.Exit()). I obviously don't want any reference counting here, and I don't want the script to create an instance of it. How do I go about doing this? I got a little lost in the docs - I'll be honest! Cheers

Share this post


Link to post
Share on other sites
hi

you can register TKernel as zero-size class and then register "TKernel Kernel" as global property, reference counting is not needed and users can't create other TKernel objects, while you can register some methods (like that Exit())
(i did it that way in my engine, but i have never tested it for nasty scripts)

hans

Share this post


Link to post
Share on other sites
Ooh! Good to hear!

Do you have the code snipets for registering it like this? I'm a little lost with the docs atm :(

Cheers

Share this post


Link to post
Share on other sites
behc is right. This is the way you would do it:


engine->RegisterObjectType("TKernel", 0, 0);
engine->RegisterObjectMethod("TKernel", "void Exit()", asMETHOD(TKernel, Exit), asCALL_THISCALL);
engine->RegisterGlobalProperty("TKernel Kernel", &Kernel);


Since the size of the type is registered as 0, AngelScript will not allow the scripts to instanciate variables of that type. The script will only be able to use the global property that you yourself registered from your application.

--

I realize that it can be quite confusing to figure out how to register your object types, and I'll be working on making it more intuitive on how to register objects for different uses. Perhaps, when I complete all the bug fixes for version 2.8.1 and release it I'll start working on that.

Regards,
Andreas

Share this post


Link to post
Share on other sites

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