lua-users home
lua-l archive

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


The global table contains entries for all global objects, including functions.  Lua threads inherit their environment from the parent state.  This includes the global table.  Global objects stay resident in the table until they are replaced or set to nil, so yes you can access functions later.
 
You can't run a function within a script without executing the script.  That doesn't make any sense, because the functions aren't created until the script is executed.  Unless the line "f = function () end" is executed, f is not a function.
 
Also, lua_dofile is deprecated.  Don't use it.  Use luaL_loadfile and lua_call instead.

________________________________

From: lua-bounces@bazar2.conectiva.com.br on behalf of John Klimek
Sent: Wed 12/21/2005 6:34 PM
To: Lua list
Subject: Lua threads share global data?



In case nobody saw my last e-mail (from the "Is lua thread safe?"), I
have some more questions... (on top of the questions asked in my last
e-mail)

1) If I create a lua thread, is the global data shared with the main
lua state?  The manual seems to contrict itself and says that the data
IS shared but then it says it's not.  From doing some tests, it seems
like the data IS in fact shared.

For example, if I load a script (using lua_dofile) and run it on my
thread, the script's global functions show up in my main lua states
global table.

My main goal is this...

In my game I will have tons of scripts being run but I need Lua to
know the current user (or NPC or object) running the script.  I can
create a global "CurrentUser" userdata but since it's global it is
shared and gets overwritten.  I tried creating a thread but that
doesn't seem to help me at all...

2) Once a script is run via lua_dofile(), all functions that were
declared stay in the global table, right?  So I can access them later?

3) How can I load a script and NOT execute it but only run a function
contained inside of that script?


Also, if anybody could answer any of the questions from my last e-mail
(about lua beiing thread safe) I would greatly appriciate it.

Thanks!



<<winmail.dat>>