lua-users home
lua-l archive

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


Peter, 

This goes back to one of my original queries:

I have this text of a lua script:

"function main()
   print("hello")
end"


And if I lua_load it, lua puts an implied function around it, which gets
left on the stack.  So if I:

Lua_laod()
Lua_call()

It executes the implied function and not main.

As I thought (but which doesn¹t seem to be the case), I was seeing if
lua_load would register "main" in the global name space.  If so, I could
then get it on the stack and call it.

But alas, after lua_loading and looking for main, I get nil on the stack.

Any suggestions?

Thx,
Ando


> 
> You need to call the function left on the stack by lua_load.
> 
> Ando Sonenblick wrote:
>>     result = lua_load(itsLuaState, LuaEngineChunkReader, this,"")
> 
>               || lua_pcall(L, 0, 0, 0);  /* ADD THIS HERE !!! */
> 
>>     if (result == kNoError)
>>         {
>>         lua_pushstring(itsLuaState, "main");
>>         lua_gettable(itsLuaState, LUA_GLOBALSINDEX);
>>         if (lua_isnil(itsLuaState, -1) == false)
>>             lua_call(itsLuaState, 0, 0);
>>         }

-----------------
SpriTec Software
www.spritec.com