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.

Now... if, for instance, we altered this code in anyway and had to commit this to a git repository, we would end up having to push the whole binary to it. Which is quite bad. We would like this script to actually be outside of the .ttt, in its own .lua file. So...

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:

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?

if not __notFirst__ then local file='/testScene_Cuboid_Non_Threaded.lua' local scenePath=simGetStringParameter(sim_stringparam_scene_path) __notFirst__=true __scriptCodeToRun__=assert(loadfile(scenePath..file)) if cmd then local tmp=assert(loadstring(cmd)) if tmp then tmp() end endendif __scriptCodeToRun__ then __scriptCodeToRun__()end