Advertisement

Register system function after build

Started by April 05, 2015 10:00 PM
2 comments, last by WitchLord 9 years, 7 months ago

I was try create app function, which dinamically register global function, whith name, signatures and address sended as arguments.

And than return created function as funcdef handle. Function registered without error, but programm is crashed after calling that from script.

I was investigate - for created function not called PrepareSystemFunction. After I was call it, its work correctly. But PrepareSystemFunction call only from PrepareEngine, and after build first module, all added after that app function stay unprepared?

Hi Alexander,

I haven't designed the library with this case in mind. Currently it is possible to register new functions and object types after the first script has been build, and they will be prepared upon the next request to build a script.

To work around your current situation you can simply build an empty module right after registering the new function. That will prepare the function and allow it to be called from the script that registered it.

However, I'll investigate what can be changed in the library to make this case work without the need to do the 'fake' build.

May I ask how your script know how to register application functions? Can't you register the function even before building the script the first time?

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

Advertisement

Thanks for reply, Andreas.

I will try some redisign my architecture for it.

I create some extention/plugin programm for some commercial app, which not have public documented api, and their "liver" little changed from version to version.

And users may have and worked with any different version of that app, sometimes even at the same time.

At first I wrote in C++, but now support interoperability with multiple versions at the same time - has turned into hell - changed func address, signatures, virtual table order, offsets in structs and many others.

So I decided to port my software to the AngelScript.

Now core of my programm first created some intermediate layer for call native function from extending app, and than run script on AngelScript.

And intermediate layer partially prepared with module on AngelScript too - I was simply register in script engine some of their "RegisterNNN" func :)

For example:


int registerObjectType(const CStringMy& objectName, unsigned size, unsigned typeFlags)
{
    return asEngine->RegisterObjectType(CStringA(objectName), size, typeFlags);
}
AS_FUNC(regType_as, "int registerObjectType(const string& in,uint,uint)", &registerObjectType);

int registerMethodByAddres(const CStringMy& object, const CStringMy& method, unsigned addr, unsigned cc)
{
    if (object.IsEmpty()) {
        return asEngine->RegisterGlobalFunction(CStringA(method), asFUNCTION(addr), cc, 0);
    } else {
        asSFuncPtr p(3);
        *(unsigned*)p.ptr.dummy = addr;
        return asEngine->RegisterObjectMethod(CStringA(object), CStringA(method), p, cc, 0);
    }
}
AS_FUNC(regMetAddr_as, "int registerMethodByAddress(const string& in,const string& in,uint,uint)", &registerMethodByAddres);

First I created "compatible" module and run it, it register API functions depending on version of running parent app, and than I create main module, which do main work.

But now I have developed some kind of declarative description for the creation of an intermediate layer for different versions, and the need for such a decision unnecessary.

It's good to know you've worked around the problem. :)

I will still look into changing the code to support doing what you tried originally.

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