lua-users home
lua-l archive

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


Hello there, 
I'm using the require function from a C program to load lua functions 
and evrything seems to work fine. 
I'm running lua version 5.0.2 
As I read on the manual, 
<<require keeps a table with the names of all loaded files. If a 
required file is already in the table, require simply returns. So if I 
overwrite a lua file containing a function, to get the new version I 
must restart the program. 
As I read in the Lua manual, after a successful require"foo", 
_LOADED["foo"] will not be nil. If you then assign nil to 
_LOADED["foo"], a subsequent require"foo" will run the file again.>> 

With this in mind, my aim was to do something like 
_LOADED[funcname] = nil everytime I overwrite the file. 


My problem is that I'm not able to access this table from my C 
program, i.e. I do something like 
lua_getglobal(L, "_LOADED"); 
if (!lua_istable(L, -1)) 
{printf"_LOADED is not a valid table"); exit(0);} 
n = lua_getn(L, -1); n IS ALWAYS ZERO !!!!!! 


I try to read my element in the following way: 


lua_getglobal(L, "_LOADED"); 
if (!lua_istable(L, -1)) 
{printf"_LOADED is not a valid table"); exit(0);} 
lua_pushstring(L, funcname); 
lua_gettable(L, -2); 
if (!lua_isstring(L, -1)) 
printf("invalid component in _LOADED"); 
else 
myname = lua_tostring(L, -1); 
lua_pop(L, 1); 


But I always get the message invalid component. 


I run the require function before so I expected to find something in 
the _LOADED table. 
Can anybody please help me to change the _LOADED[] table values from 
my C program. 


Thank you in advance 
-- 

-- 
View this message in context: http://www.nabble.com/Lua-require-function-and-_LOADED-table-tf3225748.html#a8960290
Sent from the Lua - General mailing list archive at Nabble.com.