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():
self.myVariable = 21
def sysCall_sensing():
print(self.myVariable)
--lua
function sysCall_init()
myVariable = 21
end
function sysCall_sensing()
print(myVariable)
end
#python
#luaExec wrapper = 'myWrapperCode' -- looks for myWrapperCode.lua in Lua's search path
#luaExec pythonExecutable = 'c:/python38/python.exe' -- runs a specific Python executable
#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()
print('hello Paul!')
sim.callScriptFunction('myPythonFunction', sim.handle_self)
end
'''
def myPythonFunction():
print('hello Jeanine!')
def sysCall_init():
sim = require('sim')
sim.callScriptFunction('myLuaFunction', sim.handle_self)
print("hello Marc!")
#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'}
--lua
require('myExternalFile')
#python
def sysCall_thread():
xml = '<ui title="Custom UI"> <button text="Click me!" on-click="click_callback"/> </ui>'
ui = simUI.create(xml)
while not sim.getThreadExistRequest():
sim.handleExtCalls()
simUI.destroy(ui)
def click_callback(ui,button):
print("button was clicked!")
--lua
function sysCall_thread()
xml = '<ui title="Custom UI"> <button text="Click me!" on-click="click_callback"/> </ui>'
ui = simUI.create(xml)
while not sim.getThreadExistRequest() do
sim.handleExtCalls() -- optional
end
simUI.destroy(ui)
end
function click_callback(ui, button)
print("button was clicked!")
end
#python
def sysCall_thread():
sim.acquireLock()
# perform some task that involves CoppeliaSim
sim.releaseLock()
#python
#luaExec contactCallback = true -- enable contact callback
#luaExec dynCallback = true -- enable dyn callback
#luaExec eventCallback = true -- enable event callback
def sysCall_contact(inArg):
print(inArg)
def sysCall_dyn(inArg):
print(inArg)
def sysCall_event(inArg):
print(inArg)
|