Ok, i know there has been several threads about embedding Lua in C, but i was wondering if someone could expound a bit on what that might avail the programmer specifically. Let's say in a ROM or SMAUG project, what might some code look like? I know Aardwolf uses Lua as mobprog scripting for builders. Also, would it be suited to develop commands?
An entire forum devoted to (one) implementation of Lua in SMAUG. Nick uses a single global state, though, but I don't know enough to state the pros/cons of that versus something like a state per player (or object).
Actually he uses a state per player for a lot of the interesting things, and a global state for other things. The embedding he has is not a full embedding where you can treat characters as first-class objects. If you read those forums you'll note that we talk about this for quite a bit. :smile: That said, it's a very good example for getting started.
As for what Lua gives you, well, it gives you a sane and far more powerful "mudprog" environment; it gives you a language that you can implement actual game logic in, including commands; and of course all the advantages of dynamic languages when working in a C/C++ environment.
Out of curiosity, has anyone attempted embedding Lua in Lua? Lua seems quite mature enough to use for a driver, and I always consider it a plus if the driver itself uses the same language (and utility code) as the game objects. However, for security reasons, you don't really want a program attached to an sword to be able to call arbitrary functions (such as I/O, threading, etc).
Since it seems to be fairly easy to pass things around from C to Lua, how easy is it to sandbox a Lua interpreter from another Lua interpreter?
Well, the thing is that you can already create restricted execution environments for functions to run in, so you wouldn't need to create a sandboxed interpreter from inside another interpreter. But sure, plenty of people working with Lua have done this sort of thing. I haven't done it personally to implement a driver/scripting separation, however I have used restricted environments for other reasons and down the line restricting scripts will be one application.
I have done this sort of thing, in my Lua project I've been working on, all the game logic is in Lua, and I wanted builders to be able to make scripts for things such as mob progs, all the way to commands to enhance areas in some special way, so I built a sandbox inside of Lua to run Lua scripts built by builders, with its own _G array as to not write over the cores.
You will probably have trouble implementing interesting commands without a deeper embedding (one where character handles can be passed around as values). To answer your question, though, ROM isn't different enough that it would be terribly complex to adapt the Lua embedding.