lua-users home
lua-l archive

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


I apologise if this has been covered before and I realise it's a complete newbie
question, but I code for a MUD that has begun utilising Lua to remove some of
the overhead the code is creating.

I have some general knowledge of C and some basic knowledge of Lua and its uses,
but I have been unable to define a table (within C) and then reference the table
from a script. As an example, I have a single entity (a room within the MUD)
which can contain a number of objects or people and I wish to create two tables
for these and attach them to the room entity.

To date, what I have is:
  lua_newtable(L);
  for (i = 1, ppl = room->people; ppl; i++, ppl = ppl->next_in_room) {
    lua_pushstring(L, "ppl"); lua_pushuserdata(L, ppl); lua_rawseti(L, 1, i);
  }
  lua_pushstring(L, "struct"); lua_pushuserdata(L, room); lua_settable(L, -3);

Firstly, is this correct? Can I then reference the people within the room from
the script? Along a more advanced line, how can I then define these "people" as
tables themselves, a table within a table so to speak?