lua-users home
lua-l archive

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


The key here lies in better understanding what luaL_loadbuffer does.
It "loads" the code, but does not execute it (which would give it the
opportunity to set globals such as "read").
Essentially luaL_loadbuffer returns on the stack a function whose body
consists of the loaded code, you can then call this function to run it (or
store it off in some table, or whatever).

Checking the manual/sources/and the list archives for lua_dobuffer should
help you better understand this (provided it doesn't swamp you with
results).  Looking directly at the source for lua_dobuffer should help.

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Stoil Todorov
Sent: Wednesday, December 17, 2003 11:12 AM
To: Lua list
Subject:


Hi ,
I have the problem with load/call Lua code:-(
I follow the next order:
1. luaL_loadbuffer(...)
2. lua_getglobal(m_pLuaState, "read");
3. lua_pcall( m_pLuaState, 0, 0, 0 );
but I receive "A runtime error.: attempt to call a nil
value" - t.e. function "read" is not in Global state,
but I see it is in string, which I loaded...:-(
I load string with this code:
luaL_loadbuffer(m_pLuaState, m_strCode,
m_strCode.GetLength(), (LPCTSTR)m_strCode);

Sorry about this "beginner" question and thank you in
advance...
Stoil



__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/