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 http://www.forum.coppeliarobotics.com/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
while simGetSimulationState()~=sim_simulation_advancing_abouttostop do
simSwitchThread() -- resume in next simulation step
Nothing fancy, this code just initializes a variable called myVariable, an adds up 1 in a loop while printing it. If you play the scene you should see something like this:
- 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 sceneName = string.gsub(sceneFullName, ".ttt", "_")
selfName = string.gsub(selfName, "#"..nameSuffix, "")
local file = assert(loadfile(filenamepath))
This code builds the name of the lua file we want to access (i.e. "filenamepath") based on the scene's name and the name of the object the script is attached to.
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.