lua-users home
lua-l archive

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


I haven't tried that yet, but it could be viable;

however i'd rather not have to define the locals in the script; that is it would be nice to be able to automatically define a local and set it from the C API; any ideas?



On Fri, Feb 15, 2008 at 2:09 PM, Eike Decker <eike@cube3d.de> wrote:
Hi
I don't know about the C API documentation but I guess it's in the manual,
however if you have a file that starts like this:

-- script.lua
local arg1,arg2,arg3 = ...
print(arg1,arg2,arg3)

and execute it with "dofile('script.lua','hello','world','!')" you will pass
these arguments to the file as arguments.

Eike

> Greetings all,
>
> I have a lua script file, which contains code and several functions; i'm
> executing this script from C using essentially luaL_dofile.
>
> what I would like to be able to do is pass in some parameters that have
> local scope (as if I had declared them as locals)
> but I don't want to wrap the code inside of a function.
>
> I don't want to use a global, because functions called within this script
> could cause other scripts to be executed, which would change this global
> variable, and on return it would no longer be the same.
>
> My actual example is needing to be able to set a local parameter 'this' to
> some number, so that the script has context about what object is making it
> run.
>
> any help would be great, thanks :)
>
> -Raymond Jacobs
>