[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_getglobal / lua_pcall - can't find my function
- From: "Abhinav Lele" <abhinav.lele@...>
- Date: Fri, 2 May 2008 11:21:39 +0530
you need to call pcall(L,0,0,0) after loading your file before u use
the function.
have a look at http://code.google.com/p/openanimator/source/browse/trunk/engine/src/engine.h:
LuaEnviroment class to get a howto for your problem.
On Thu, May 1, 2008 at 6:58 PM, Aaron Saarela
<Aaron.Saarela@emergent.net> wrote:
> Hi,
>
> I have some lua functions I want to call from a C++ application. I use
> lua_dofile to load the file. If I use lua_dostring to call a function it
> works fine. However, when I use lua_getglobal/lua_pcall instead, my function
> doesn't end up on the stack and pcall fails with a call to nil.
>
> Here's an example of what I'm talking about:
>
> // get the foo module ready to go
> lua_dofile(state, "foo.lua");
> luaL_dostring(state, "foo.dosomething()"); // works fine
>
>
> But:
>
> lua_getglobal(state, "foo.dosomething");
> lua_pcall(state, 0, 0, 0);
> // returns -1, err message indicates a call to nil
>
>
> my foo.lua looks like:
>
> module("foo", package.seeall)
>
> function foo()
> print("Did something")
> end
>
>
> Is there something I'm missing?
>
> Thanks,
> -Aaron
>
>