Regular API function

simRegisterScriptVariable

Description
Registers a script variable. Each time a script is run for the first time, registered variables will be set. The registered variable names will also be used for syntax highlighting and auto-completion purpose in the CoppeliaSim code editor. Can also be used for more complex operations as in following example:
simRegisterScriptVariable("simUi","require('customUi')",0);
which is equivalent with an implicit simUi=require('customUi') command in the initialization phase of every script.
C synopsis simInt simRegisterScriptVariable(const simChar* varNameAtPluginName,const simChar* varValue,int stackhandle)
C parameters
varNameAtPluginName: name of the variable, combined with the plugin name: variableName@pluginName. Avoid using too simple variable names, otherwise they might clash with other plugins. Also, always use the simXX. prefix (e.g. simMyPlugin.myCustomVariable) for the variable name. The plugin name should be the exact same name used while loading the plugin via simLoadModule (if the plugin name is simExtMyPlugin.dll, this should be MyPlugin).
varValue: value of the variable. Can be nullptr, in which case the value of the variable will be the top item of the provided stack (or, if stackHandle is 0, varName will only be used for code auto-completion purpose).
stackHandle: a stack handle obtained with simCreateStack. Set to 0 if varValue is not nullptr. Set to -1 if varValue is not nullptr and you do not want the variable to appear in the script editor auto-completion list. If a stack is provided, it will be released at a later point by CoppeliaSim.
C return value
1 if the variable was registered, 0 if the variable was replaced because it already existed, -1 in case of an error
Lua synopsis
int result=sim.registerScriptVariable(string varName)
Lua parameters
varName: name of the variable. The Lua version of this function will only be used for syntax highlighting and auto-completion purpose in the CoppeliaSim code editor
Lua return values
result: 1 if the variable was registered, 0 if the variable was replaced because it already existed