[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: executing functions from file, without using luaL_dofile
- From: HyperHacker <hyperhacker@...>
- Date: Sun, 1 May 2011 16:31:42 -0600
On Sun, May 1, 2011 at 09:54, jseb <gmane2010@finiderire.com> wrote:
> Hello,
>
> I'm trying to load a Lua script from a C file, without executing it at load
> time.
> In other words, i don't want to use "luaL_dofile (L, script.lua)".
>
> So i use instead "luaL_loadfile (L, "script.lua") "
>
> But after loading the script file, how can i execute "foo" function from
> inside it ?
>
> i tried this:
>
> lua_getglobal(L, "foo");
> lua_pcall (L,0,0,0); //compile function
> lua_getfield (L, LUA_GLOBALSINDEX,"foo");
> lua_pcall (L, 0,0,0); //execute function
>
> but the function is not executed.
>
>
> Thank you.
>
>
>
In Lua, writing "function foo() ... end" is really a shortcut for "foo
= function() ... end". Just like any other variable assignment, that
won't do anything until the statement actually gets executed.
Why do you not want to execute the file, but you want to load (and
presumably execute) the functions defined in it? Perhaps you want to
look at sandboxing.
--
Sent from my toaster.