Advertisement

CompileFunction question

Started by April 14, 2014 02:14 PM
1 comment, last by gjl 10 years, 7 months ago

Hi,

I have noticed that adding a function using the CompileFunction method is not equivalent to adding the same function using AddScriptSection: when using CompileFunction, even with the asCOMP_ADD_TO_MODULE, it is not available from sections that may be added to the module and compiled later. Is this expected?

int r=module->CompileFunction("KittyPrivate","void print(const string &s){}",-1,asCOMP_ADD_TO_MODULE,NULL);assert(r>=0);

int r=module->AddScriptSection("KittyPrivate", "void print(const string &s){}");assert(r>=0);

Also, as a side note, it seems that adding the same global function using first CompileFunction and then as part of a Script section does not raise any error (I guess the second one just overrides the first silently). That's perfect for what I am doing, but I'd prefer to check that this is the expected behavior!

The AddScriptSection() call doesn't do any processing of the script section. It will just put the script code in the list of sections that should be compiled when the next call to Build() is made.

The call to Build() will remove all previously compiled code in the module, including that which has been added dynamically with CompileFunction(), and then rebuild everything from the script sections.

When calling CompileFunction() with asCOMP_ADD_TO_MODULE, it will include the newly compiled function in the module, so that it can be found with the GetFunction???() methods. It will also be visible to subsequent calls to CompileFunction() so that a second dynamically compiled function can call the previous one.

I'll improve the documentation to make this behaviour more clear.

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

Ah ok, thanks, it makes sense now! The missing part for me was that Build() removes all previously compiled code.

This topic is closed to new replies.

Advertisement