lua-users home
lua-l archive

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


Alright!

I ll try to b more precise!

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


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Ive
Sent: Saturday, July 16, 2005 12:12 PM
To: 'Lua list'
Subject: RE: lua_State and garbage collection


Hi all!

How do you Init an ai script?

And how do you update it...


Ive tried init like with:

luaL_loadfile(LUA()->m_lua, "primitive_cubeAI.lua");

and call it everyframe with:

lua_call(LUA()->m_lua, 0, LUA_MULTRET);

is this the right way to do this?

thx