I did a little experiment on Lua Pre Compiling...

BlitzMax Forums/BlitzMax Programming/I did a little experiment on Lua Pre Compiling...

Tricky(Posted 2011) [#1]
Perhaps MaxLua is not the best way to try this in, but what the heck, I tried and the results are error, still interesting, though...

For this experiment I just used the MaxLua example program and modified it for the needs of the expirement
Const sf$ = "<file name>"
Local source$=LoadString(sf) ' ,FileSize(sf)) 
Print "Source is "+Len(Source)
Local class:TLuaClass=TLuaClass.Create( source )
Local instance:TLuaObject=TLuaObject.Create( class,Null )
If instance instance.Invoke "Test",Null


And now for the LUA source

-- test
function Test()
for ak=1,1000 do
print(ak)
end
end



Well, when I run the lua code just directly from the lua source file it will just count from 1 till 1000, no problem there. But now I precompiled it (using luac) and ran the precompiled coded and I got the following error

Error loading script :
binary string: unexpected end in precompiled chunk


Well, according the the Len function I used in my BMax code the source is as big as the file, so no bytes could be missed, second does the Create function ask for a strings and strings alone, so no other way to put it in, and clearly LUA recognizes precompiled script and source script automatically as the error shows.



It's not that this error will disturb my project too much as precompiled scripts are not needed in it, but I really wonder if this can still be done somehow using MaxLua, though....


JoshK(Posted 2011) [#2]
LuaJIT is incompatible with precompiled files, and if you are using Lua you should use LuaJIT.