calling script function from a C++ module

kaleryankaleryan Posts: 4Member
edited August 2016 in Programming
Hello,<br /><br />I'm trying to create a module in C++ and I would like to call a function with a specific name and its arguments from a C++ method.<br /><br />In this method, I've got the GDScript* and the CanvasItem* for which this script is defined, but I cannot figure out how to use the "GDFunction::call" method provided in gd_script.h. Note that the script function I'm trying to call is non static.<br />I manage to list all the functions available for the GDSCript*, but I cannot get any relevant GDInstance* required to call the "call" function.<br /><br />Is there any way to perform such function call more easily ?<br />or else is there any way to get a relevant GDInstance* to use the existing GDFunction::call method ?<br /><br />Thank you by advance ...<br /><br />(already posted in the editor plugin category, but this place seems more relevant)

Tags :


  • kaleryankaleryan Posts: 4Member
    Ok, I've finally figured out how to get this GDInstance*.<br />I use Object::get_script_instance on the Node2D I have, and dynamic_cast it to GDInstance...<br />Then, I use the GDInstance::call method, and that's it.
  • KioriKiori Posts: 246Member
    @kaleryan, if you post in the "wrong" section, please report your own post and request it to be moved. ;)
  • ZylannZylann Posts: 16Member
    You shouldn't cast the ScriptInstance to GDInstance because it breaks script language independence: for example, if someone implements Lua or C# as alternate scripting language it won't work with your module. call() on ScriptInstance should just work fine.<br />Just saying :)<br />
  • kaleryankaleryan Posts: 4Member
    You're absolutely right :)<br /><br />I was so happy to have a working solution that I did not check the obvious (the GDInstance::call function is virtual) and I did not delete this ugly cast, till now.<br />Thanks!
Sign In or Register to comment.