lua-users home
lua-l archive

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


Am I at the right place to discuss this?

...

Alright!

What I m trying to do is to assign to each actor in a game environment a
script ai!

I m wondering if I must do:

lua_State *m_lua;

	if ((m_lua = lua_open()) == NULL)
	{
		Trace("ERROR: LUA initialization failed!\n\n");
	}
	else
	{
		Trace("TELL: LUA initialization successful!\n\n");

		luaopen_base(m_lua);
		luaopen_table(m_lua);
		luaopen_io(m_lua);
		luaopen_string(m_lua);
		luaopen_math(m_lua);
		luaopen_debug(m_lua);

		RegisterFunction(); /// register all functions

	Int l_status = luaL_loadfile(m_lua, in_name.GetName());
	lua_settop(m_lua, 0);

	if (l_status != 0) 
	{
		lua_error(m_lua);
	}
	}

to each of the script!


Then update them individually each frame with:

lua_pcall(m_lua, 0, 0, 0);

or

my first guest is to have only one lua_State instance and register all
functions once and then keep track with a pointer to each
luaL_loadfile... but I cant find the way to retrieve them... can anyone
clear this up please?

Is lua_open() should be call once (then register all possible functions
once) or to all attached scripts? What is the ultimate way to do this
with out unnecessary overheads?

thx