lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jun 5, 2012 at 12:38 PM, Jeff Smith <spammealot1@live.co.uk> wrote:
> Hi
>
> I could do with a bit of help please to point me in the right direction on a
> Lua chunk loading problem.
>
> I initially had a nice simple load a lua program                 (just
> uncompiled ASCII text file)
>
> loadResult = luaL_loadfile(L, "myLuaProg.lua");
>
>
> Then I decided I wanted to store the lua program text in the C code, so I
> wrote an external utility program that turned "myLuaProg.lua" into a simple
> C lookup table source file. Once that C file was compiled into my App, I
> then Iused this to load it
>
>
>
> loadResult = luaL_loadstring(L, myLuaProg_C);   // load the text from a
> simple C lookup table
>
> So far so good that all worked fine, but then I wanted to precompile
> myLuaProg.lua into bytecode before I ran it through the utility to convert
> it to a C lookup table source file.
>
> To load the compiled program from the C lookup table I dont think I can use
> the luaL_loadstring() function, so I changed that to be
>
> loadResult = luaL_loadbuffer (L, myLuaProg_C, sizeof(myLuaProg_C),
> "myProg"); // load the bytecode from a simple C lookup table
>

Take a look at this:
http://www.lua.org/pil/24.1.html

"If there are no errors, the call returns zero and pushes the
resulting chunk on the stack."

So you now need to call that resulting chunk.