lua-users home
lua-l archive

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


Hello, I'm brand new to Lua and have unfortunately had a hard time 
finding decent or straightforward documentation on the system thus 
far. The docs at lua.org are a reasonable introduction, and the 
language itself is obviously very simple to understand and get 
familliar with. My problem has been finding good information on 
exactly how Lua interfaces with C.

First of all, I do need to use Lua in a "real-time" sense, since I'm 
using it to script my game engine and therefore need Lua code 
execution to be a concurrent and constant part of my game's main 
loop. I've read a bit on the problems associated with this, namely 
with the garbage collector causing too much overhead, but I don't do 
a whole lot of major allocation so I shouldn't have too much trouble 
as far as speed goes.

My real questions are more specific, however. I'll just run through 
them:

- First of all, how exactly do I run Lua code from within my program? 
I've been able to run scripts with lua_dofile () and all that, which 
is fine for initialization routines and other scripts that just need 
to be loaded once and immediately executed, but how would I run a 
block of code alongside my game's main loop? Basically what I'd like 
is the ability to start the execution of a given script and have that 
run until I explicitly tell it to stop. Since I know Lua itself isn't 
multithreaded in any way, I'd expect to have to run a perpetuating 
function at each iteration of my loop (or something), but I can't 
find anything like this in the documentation. All I can find are ways 
to run whole scripts in a single burst.

- How do I load code for future use? lua_dofile () just seems to load 
the code once and then immediately execute it. I need to know how to 
load a script without executing it and let it sit in memory until I 
need it, at which point I can call Lua functions directly, read/write 
global variables, or whatever. Also, is this generally how Lua is 
used in real time purposes? In other words, do most games (and other 
real-time apps) simply load a script at the time of initialization 
and then manually call a DoFrame ()-type Lua function explicitly each 
time through their game's loop? That'd work fine for me, so any 
details on how this works would be great.

- lua_dobuff () executes a buffer of compiled Lua code in memory, but 
how do you get this buffer in the first place? I can't find any 
functions for just loading a Lua binary into memory, and I doubt I 
have to go as far as writing a compiled Lua script loader just to 
extract this data.

Thanks in advance for any help you guys can offer. :) Also, I'm only 
a newbie as far as Lua goes, so feel free to go into as much detail 
as necessary. I'm also interested in under-the-hood info on Lua as 
well, so if any references to low-level VM-related stuff would be 
apprecaited. :)

--DJM