PDA

View Full Version : Script loading sequence



bullno1
09-03-2008, 08:30 AM
Here's the pseudo-code to demonstrate how torque game builder run a script

When main.lua is run


if(exist file main.lua)
{
if(exist file main.lua.comp) //the bytecode-compiled version of main.lua
{
if(main.lua.comp is up-to-date)//this is done by checking the last modified date
loadAndRun(main.lua.comp)//use this because we can by-pass the compilation phase
else
compileAndRun(main.lua.comp)//update the compiled file
}
else//if there is no bytecode version
{
compileAndRun(main.lua.comp)//create it
}
}
else//if main.lua is not found
{
if(exist file main.lua.comp)//search for the bytecode version
loadAndRun(main.lua.comp)//run it
else
return error;
}


IMO Novashell should adopt this system
It saves time since unedited script are compiled for faster loading. And by distributing only the compiled scripts, we can hide our source code from end-users. Script compilation in Lua is simple, you can refer to the source code of luac (the lua compiler) . Fortunately, in LUA ,the same function is used for running plain-text and precompiled script.

Seth
09-03-2008, 11:22 AM
I totally agree, and that's pretty similar to how I would do it.

But I was thinking to use main.lad or something instead of main.lua.comp because I'm afraid having two "."'s in a file name will cause problems somewhere on one of the platforms.

Btw I had no idea TGB now works with lua, that's pretty cool, big step up from torquescript imo.

It should be quick and painless to add, just haven't really worried about it yet but it is on the list.

bullno1
09-03-2008, 12:23 PM
Btw I had no idea TGB now works with lua, that's pretty cool, big step up from torquescript imo.
No it doesn't I just somehow forgot the torquescript's extension :p so I used .lua instead and make up the .lua.comp thing