[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple Lua Script Files
- From: Pavel Antokolsky aka Zigmar <zigmar@...>
- Date: Sun, 15 Jan 2006 09:16:32 +0200
Hi,
Why to use globals? Why not to store the relevant information inside
the Lua state itself, for example in regisrty (if you don't want the
scipts been able to access it)?
For example
lua_pushstring(L1,file1);
lua_setfield(L1,LUA_REGISTRYINDEX,"scipt_filename");
lua_pushstring(L2,file2);
lua_setfield(L2,LUA_REGISTRYINDEX,"scipt_filename");
lua_dofile(L1, file1);
lua_dofile(L2, file2);
...
int my_c_function(lua_State *L)
{
lua_getfield(L,LUA_REGISTRYINDEX,"scipt_filename");
const char* script_name = lua_tostring(L,-1);
...
}
On 1/14/06, CHU Run-min <churunmin@gmail.com> wrote:
> #define FILE_1 1
> #define FILE_2 2
>
> int current_file;
>
> current_file = FILE_1;
> lua_dofile(L1, "file_1")
> current_file = FILE_2;
> lua_dofile(L2, "file_1")
>
> int my_c_function(lua_State *L)
> {
> if (current_file == FILE_1)
> printf("file 1 made the call");
> else if (current_file == FILE_2)
> printf("file 2 made the call");
> }
>
--
Best regards,
Zigmar