Page 1 of 1

[solved]Lua question

Posted: Mon Dec 19, 2011 12:31 pm
by REDDemon
how is it possible to load bytecode and lua files from c++ using irrlicht interface?

I want to use the

Code: Select all

 
lua_load
 
function

this is usefull because it should read a lua program directly from a ram memory buffer, but I'm stuck on how to get the C string from the "helloworld.lua" file wich is putted into and compressed archive ("script.zip") wich is opened by irrlicht. So my problem is to get the C string from a file using irrlicht. I tried something but seems that some characters are changed during loading.

Re: Lua question

Posted: Mon Dec 19, 2011 4:44 pm
by Radikalizm
I did it like this:

You use a regular IReadFile to read in the contents of your lua file (binary or text, doesnt matter) into a buffer
Then you can use luaL_loadbuffer and pass it the buffer you created with the IReadFile and it will handle everything for you

The lua documentation can be quite confusing sometimes

I assume this is what you were talking about?

Re: Lua question

Posted: Mon Dec 19, 2011 5:29 pm
by REDDemon
exactly the expected answer! thanks! so I should use something like:

Code: Select all

 
long size= file->getSize();
char * str = new char[size];
file->read(str,size);
luaL_loadbuffer(L,str,size,filename);
delete str;
 
I will try immediatly.