lua-users home
lua-l archive

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


Hi
 
Internet law number 1, as soon as you post a question asking for assistance on something, you spot your silly mistake two seconds later. :)
 
I think I was correct in switching from lualoadstring() to  luaL_loadbuffer()  but I had forgotten that my header file for the lookup table was
 
extern const char myLuaProg_C[];
 
I had forgotten it was an implicit array size definition, so of course in my dumb code I was passing sizeof(myLuaProg_C) which was zero.
 
its a bit of a pain to resolve neatly as I think I need to rewrite my external conversion utility so that if its input file is a lua source file (text) then it writes the C file out as Null terminated string (in source code form). Conversely if it sees the input file is a lua binary chunk it needs to write it to the C table as  non NULL terminated and also include the source code for a "getter" function to return the size of the C lookuptable.
 
 
Jeff
 

From: spammealot1@live.co.uk
To: lua-l@lists.lua.org
Date: Tue, 5 Jun 2012 16:38:56 +0100
Subject: Need a bit of help with a lua loading problem please

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
 
This didnt crash, it returns 0 OK, but the code does nothing. I am guessing I am misunderstanding this and using the wrong function here ?
 
Any thoughts would be appreciated. Thanks
 
Jeff