lua-users home
lua-l archive

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


I've searched through the archives and it has been very useful in getting
me started with lua. I'm at a bit of an impass right now and am hoping
someone on the list can help.

Currently I am opening a lua_State, registering all of my C functions with
that, and then creating a new thread for each entity I need using
lua_newthread(). Subsequent to creatring a new thread, I load a script
to be run by that thread, and then use lua_getglobal(thread, "funcname")
to find the function I want to call in the script. then I call
This works perfectly as long as the function name is unique. The problem
I would like to have each script have an Initialize() function.
Unfortunately, the Initialize() lua function of whichever script was last
loaded gets called no matter which lua thread I am resuming.

What is the proper way of doing this? My application, like so many others,
is in a game system where I would like to be able to create new game
entities, attach a lua script to then, and let the script run, using
from within C functions to yield the scripts. I also would like to keep my
names identical across all scripts to simplify the calling interface from
C code.
I've tried using multiple lua_open() calls to create seperate lua_States
for each entity,
but then I have to register my C Functions for each new entity. This seems
expensive since we are targetting the console market where memory and
speed are a key requirement.

I've seen some details in the archives but they all use lua_cobegin() a
function that
is no longer available in lua-5.0.

Any tips or even pointers to previous message threads about this would be
great. If worse
comes the worse I can create a new lua_State using lua_open() for each
object, but that
seems like too much overhead, what with having to register the C functions
each time.

Many thanks for your time.

Steven Brekelmans