I've been wanting to add Lua into SWR (a branch of Smaug) for years now, but after seeing what Aardwolf has done I think it's time to quit stalling.
I am not very good with Lua's C API as of yet, but I am getting better. The whole stack thing was confusing at first, but I think I've got a solid grasp of the mechanics now. However, I still don't know enough. I would like to write an implementation similar to Aardwolf's, but I am unsure of how to do something like:
name = ch.name
level = ch.level
...
Where it doesn't keep 2 copies of the data, but rather retrieves the data from C on the fly. That seems cleaner than Nick's original method of something like:
level = mud.getlevel(ch)
...
Initially I intend to use just one Lua state. So the other issue I'm up against is how to separate scripts properly, such as having say, two functions called "on_enter" for two different room vnums. The Aardwolf fellow mentioned something about using a map to track all the various scripts. Would that work with "luaL_loadbuffer"?
Also, just as an FYI, my intent is to use Lua for not only hooks in various places, but also as mob spec_funs, and localized commands attached to rooms, objects, mobs.
So I guess to get to the point: What C code is needed to allow you to do something like "level = ch.level"? Do you have any recommendations on tracking individual scripts? Is "luaL_loadbuffer" good for loading separate scripts stored in "const char *"? Though it might be better to just load files instead. Not sure.
I am not very good with Lua's C API as of yet, but I am getting better. The whole stack thing was confusing at first, but I think I've got a solid grasp of the mechanics now. However, I still don't know enough. I would like to write an implementation similar to Aardwolf's, but I am unsure of how to do something like:
name = ch.name
level = ch.level
...
Where it doesn't keep 2 copies of the data, but rather retrieves the data from C on the fly. That seems cleaner than Nick's original method of something like:
level = mud.getlevel(ch)
...
Initially I intend to use just one Lua state. So the other issue I'm up against is how to separate scripts properly, such as having say, two functions called "on_enter" for two different room vnums. The Aardwolf fellow mentioned something about using a map to track all the various scripts. Would that work with "luaL_loadbuffer"?
Also, just as an FYI, my intent is to use Lua for not only hooks in various places, but also as mob spec_funs, and localized commands attached to rooms, objects, mobs.
So I guess to get to the point: What C code is needed to allow you to do something like "level = ch.level"? Do you have any recommendations on tracking individual scripts? Is "luaL_loadbuffer" good for loading separate scripts stored in "const char *"? Though it might be better to just load files instead. Not sure.