Advertisement Jump to content
Sign in to follow this  
gjl

CompileFunction question

This topic is 1743 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,

 

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!

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!