lua-users home
lua-l archive

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


Hi,

I'm just trying to use lua-gtk ... with lua 5.1 and I almost suceed.
The problem I have is that the function luaL_loadbuffer don't want to
accept my precompiled lua chunks.

So I decided to test separately this function with precompiled chinks.
I created a little script that convert any file to a C char table.

I created a C programm that create a lua state and execute the script
using the char table and luaL_loadbuffer ... compiled it .... run it
and it worked w/o any problems.

Then I created a lua C library that do the same. That is in the
function luaopen_mytest just execute the lua chunk (the table).
I compiled it ... no problems
I executed : $ lua
Lua 5.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> print(require("mytest"))
not enough memory
stack traceback:
        [C]: ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?
>

I don't understand why there is this error ... Any idea ?

Then I do the same ... but instead of the luac result, I put the
original lua source code in the C table ... no problems at all !

Any idea ?

Here is my C file:
================================================================
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "test.h"  /* the table that contains the lua code */

#ifdef LIBRARY

int luaopen_mytest(lua_State *L)
{
	int res;
//	res = luaL_loadbuffer(L, "return 'ok!';    ", 15, "test.lua");
		// Works
	res = luaL_loadbuffer(L, chunk_data, chunk_size, "test.lua");
	res==0 || lua_error(L);
	lua_call(L, 0, 1);
	return 1;
}

#else

int main(int argc, char **argv)
{
	lua_State *L;
	int res;
	L = luaL_newstate();
	luaL_openlibs(L);
	res = luaL_loadbuffer(L, chunk_data, chunk_size, "test.lua");
	res==0 || lua_error(L);
	lua_call(L, 0, 1);
	return res;
}

#endif

================================================================

Thanks
Mildred

-- 
Mildred       <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]