Externalizing scripts for better version control
I have an issue in a workaround we have been using for version control of scripts.
We have been working on a way to mitigate the difficulty of using vrep simulations with version control tools.
The approach was to leave all lua scripts outside the simulation in .lua files (as suggested in another thread viewtopic.php?f=7&t=199).
This way, all modifications to scripts could be tracked by version control, and we would reduce the number of commits with modifications to the binary .ttt.
Just to give you a minimum working example, it works like this. Let's say your simulation is called "testScene.ttt":
1) Create a Cuboid, and rename it to "Cuboid_Threaded", just to make it easier to know what it is about latter.
2) Add a threaded script, with the following sample code:
Code: Select all
myVariable=0 while simGetSimulationState()~=sim_simulation_advancing_abouttostop do myVariable=myVariable+1 print("myVariable: "..myVariable) simSwitchThread() -- resume in next simulation step end
- Initializing the Bullet physics engine in plugin 'DynamicsBullet_2_78'...
Engine version: 2.78
Plugin version: 9
3) Create a lua file at the same folder as your simulation called "testScene_Cuboid_Threaded.lua"
4) Add the same aforementioned code to it and save it.
5) Now, go back to that threaded script in Cuboid_Threaded, erase everything, and replace it by the following code:
Code: Select all
local sceneFullName=simGetStringParameter(sim_stringparam_scene_name) local sceneName = string.gsub(sceneFullName, ".ttt", "_") local objectHandle=simGetObjectAssociatedWithScript(sim_handle_self) local selfName=simGetObjectName(objectHandle) local nameSuffix=simGetNameSuffix(selfName) selfName = string.gsub(selfName, "#"..nameSuffix, "") local appPath=simGetStringParameter(sim_stringparam_scene_path) filenamepath=appPath.."/"..sceneName..selfName..".lua" local file = assert(loadfile(filenamepath)) file()
Then it uses the loadfile and file commands to load the contents inside "testScene_Cuboid_Threaded.lua" to the present script.
If you play the simulation the result should be the same we saw in step 2.
However, if we try to follow the same steps for a Non-threaded script, things get trickier. Because a non-threaded script gets called again and again, it will load the file from disk again and again too. And if you have many objects doing this you would end up with a lot of unnecessary access to disk being made many times per second.
So my question is: is there a way to perform the same (or similar) trick explained above but with non-threaded scripts?
Thanks in advance for any feedback.