Lua vs Python scriptsThe way Lua and Python scripts are handled in CoppeliaSim (next to differences related to the language itself) displays small differences, which are discussed here: #python
def sysCall_init():
print("Hello world!")
#python
#luaExec wrapper='myWrapperCode' -- looks for myWrapperCode.lua in Lua's search path
#luaExec additionalPaths={'c:/path1','c:/path2'} -- adds additional Python module search paths
#luaExec additionalIncludePaths={'c:/Python38','c:/path2'} -- adds additional paths to search for the include file
'''luaExec
function myLuaFunction()
-- do something here
end
'''
def sysCall_init():
print("Hello world!")
#python
include myExternalFile
# myExternalFile is the pythonScript name or path (absolute or relative), without quotes nor the ending '.py'
# searched paths include:
# <CoppeliaSim executable path>/
# <CoppeliaSim executable path>/python
# <current scene path>/
# <additional path>/ (see system/usrset.txt and value 'additionalPythonPath')
# additional include paths passed via #luaExec additionalIncludePaths={'c:/Python38'}
#python
def sysCall_thread():
sim.setThreadAutomaticSwitch(True)
# Do some initialization here, e.g.:
h = sim.getObject('/myCube')
originalColor = sim.getObjectColor(h,0,sim.colorcomponent_ambient_diffuse)
sim.setObjectColor(h,0,sim.colorcomponent_ambient_diffuse,[1,0,0])
# Handle the main loop here, e.g.:
while sim.getThreadExistRequest() == False:
print(sim.getObjectPosition(h,-1))
# Do some clean-up here:
sim.setObjectColor(h,0,sim.colorcomponent_ambient_diffuse,originalColor)
#python
def sysCall_thread():
sim.setThreadAutomaticSwitch(True)
while sim.getThreadExistRequest() == False:
pass
#python
def sysCall_thread():
sim.setThreadAutomaticSwitch(True)
xml ='<ui title="Custom UI"> <button text="Click me!" on-click="click_callback"/> </ui>'
ui=simUI.create(xml)
while sim.getThreadExistRequest() == False:
sim.handleExtCalls()
simUI.destroy(ui)
def click_callback(ui,button):
print("button was clicked!")
#python
'''luaExec
function myLuaFunction()
print("Hello")
end
'''
def sysCall_init():
object=sim.getScriptInt32Param(sim.handle_self,sim.scriptintparam_objecthandle)
path=sim.getObjectAlias(object,1)
sim.callScriptFunction('myLuaFunction@'+path,sim.scripttype_childscript)
|