[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Using part of a Lua script from C
- From: "Elbers, H.P." <H.P.Elbers@...>
- Date: Tue, 4 Aug 2009 09:09:21 +0200
Hi Evan,
You can test the the value of 'arg':
When using the interpreter arg[-1] will be Lua, argv[0] will be the name
of your script.
When loaded with luaL_dofile (or luaL_loadfile), arg will be nil.
--code to allow the script to run stand-alone:
if arg then
a = 1
b = 2
filter(a,b)
end
HtH, Hans Elbers.
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Evan Burkitt
> Sent: dinsdag 4 augustus 2009 6:12
> To: lua@bazar2.conectiva.com.br
> Subject: Using part of a Lua script from C
>
> I have an application that calls functions in Lua scripts
> from C (C++, actually). My design expects a certain function,
> "filter()", to exist in the scripts it uses. filter()
> typically calls other functions in the script as part of its
> behavior, but the C/C++ code doesn't know of or use these
> other functions.
>
> The scripts also contain a section of code that calls
> filter(). This exists so the script as a whole can be run
> stand-alone via the lua command line.
>
> Here's a minimal illustration of what my lua script looks like:
> --internal functions:
> function internal1() end
> function internal2() end
>
> --function called by C/C++:
> function filter(a,b)
> internal1()
> internal2()
> end
>
> --code to allow the script to run stand-alone:
> a = 1
> b = 2
> filter(a,b)
>
> When I load and compile the script via luaL_loadfile() and
> lua_pcall(), the code at the end begins to execute when I
> call lua_pcall().
>
> My question is, what is the best way to process the script
> file so that my C/C++ code can call filter() yet the entire
> script does get executed in the process?
>
> -evan
>
>