Advertisement

Question on methods...

Started by May 25, 2007 10:39 AM
3 comments, last by _Sigma 17 years, 6 months ago
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
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
Advertisement
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
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

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

Worked like a charm! Thanks for the short code WitchLord

This topic is closed to new replies.

Advertisement