lua-users home
lua-l archive

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


> What I am looking for is a way to embed lua into my application(high
level)
> Is there any way in lua that I can use to run a chunk of lua script in c
code?
>
> Can lua_load do that?

Yes.  Though you probably want to check out the luaL_loadfile and
luaL_loadbuffer calls (both declared in lauxlib.h) as well.  These leave a
closure on the stack that runs the loaded chunk when executed, or an error
message if the call fails.  Example:


/* load chunk from file */
if (luaL_loadfile(L, "myscript.lua"))
    lua_error(L);

/* run chunk */
lua_call(L, 0, 0);


There is another useful way of embedding Lua code in your C sources: use
etc/bin2c.c to translate a compiled lua file into C code that can simple be
#include-d in your source.

Bye,
Wim