Regular API function

simExecuteScriptString / sim.executeScriptString

Description Executes some Lua code in a specific script (from a plugin, the main client application, or from another script). The target script must be initialized for this call to succeed, e.g. when calling simulation scripts, then simulation must be running. See also sim.callScriptFunction.

Data exchange between a plugin and a script happens via a stack. Reading and writing arguments from/to the stack gives you a maximum of flexibility, and you wil be able to exchange also complex data structures. But it can also be tedious and error prone. Use instead the helper classes located in programming/common/stack and programming/include/stack: they will greatly simplify the task. Have a look at the example plugins simExtPluginSkeleton and simExtSkel.
C synopsis simInt simExecuteScriptString(simInt scriptHandleOrType,const simChar* stringAtScriptName,simInt stackId)
C parameters
scriptHandleOrType: the handle of the script, otherwise the type of the script:
sim_scripttype_mainscript (0): the main script.
sim_scripttype_childscript (1): a child script. In that case, stringAtScriptName should also contain the name of the object associated with the script.
sim_scripttype_customizationscript (6): a customization script. In that case, stringAtScriptName should also contain the name of the object associated with the script.
sim_scripttype_sandboxscript (8): the sandbox script.
sim.scripttype_addonscript (2): an add-on script. In that case, stringAtScriptName should also contain the name of the script (e.g. for add-on simAddOnB0RemoteApiServer.lua, B0RemoteApiServer is the script name)
stringAtScriptName: some Lua code to execute in the specified script, followed by @: "string@". If scriptHandleOrType is sim_scripttype_childscript, or sim_scripttype_customizationscript, then stringAtScriptName should also contain the name of the object associated with the script: "string@objectName".
stackId: 0 (for no stack) or a stack handle. The stack holds possible out values. See also the available stack functions.
C return value
-1 in case of an error
Lua synopsis int result,executionResult=sim.executeScriptString(string stringAtScriptName,int scriptHandleOrType)
Lua parameters
Similar to the C-function counterpart
Lua return values
result: -1 in case of an error
executionResult: return value of the executed code
Remote API equiv.
B0-based remote API: simxExecuteScriptString
Legacy remote API: -