lua global tables and require function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

lua global tables and require function

cortomaltese mf
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
Reply | Threaded
Open this post in threaded view
|

Re: lua global tables and require function

Josh Green-3
Hi, I noticed that no-one has replied to this question yet,
and I would assume that is because this is the LuaBind mailing list, that
deals with the linking of C++ objects into Lua.

You're probably better off sending this question into the lua mailing list!

Good luck!

--Josh

----Original Message Follows----
From: cortomaltese_mf <[hidden email]>
Reply-To: [hidden email]
To: [hidden email]
Subject: [luabind] lua global tables and require function
Date: Mon, 12 Feb 2007 00:13:46 -0800 (PST)


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-global-tables-and-require-function-tf3212217.html#a8920345
Sent from the Lua C++ Bind mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

_________________________________________________________________
Advertisement: 50% off on Xbox 360, PS and Nintendo Wii titles!
http://www.play-asia.com/SOap-23-83-4lab-71-bn-49-en-84-k-40-extended.html


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user