[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: accesing program vars from lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 12 Nov 2002 10:48:43 -0200
>Im very new to this, and I would like to know (with some minimal example if
>posible), how to execute a lua script from my C++ app and make it modify
>variables.
Execute a script with lua_dofile. Read and write variables with lua_getglobal
and lua_setglobal.
Here is a simple example:
-- script hi.lua
print(name)
-- C code
lua_dofile(L,"hi.lua"); /* outputs "nil" */
lua_pushstring(L,"John Lennon");
lua_setglobal(L,"name");
lua_dofile(L,"hi.lua"); /* outputs "John Lennon" */
Hope it helps you get started.
--lhf