[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [LuaInterface] Calling lua functions from c#
- From: Jason Murdick <wjmurdick@...>
- Date: Fri, 18 Sep 2009 10:56:22 -0500
I recently started trying to port an older c++ project into c# and I
am using LuaInterface 2.x and Lua 5.1. In my c++ project I passed all
of my script calls through a single lua function (executeScript) that
performed some tasks and error tracking/traceback.
The c++ side looked like this:
-----------------------------------------------------
luaL_loadfile (ScriptMgr->GetState(), path.c_str());
retcode = lua_pcall(ScriptMgr->GetState(), 0, 1, 0);
lua_getglobal(ScriptMgr->GetState(), "executeScript");
lua_pushstring(ScriptMgr->GetState(), script.c_str());
lua_pushboolean(ScriptMgr->GetState(), isFile);
retcode = lua_pcall(ScriptMgr->GetState(), 2, 1, 0);
-----------------------------------------------------
I am attempting to duplicate this in C#, but I can't figure out how to
call the executeScript global using LuaInterface. I have the
following:
--------------------------------------
pLuaVM.LoadFile(path)
LuaFunction lf = (LuaFunction)pLuaVM["executeScript"];
pLuaVM.Push(script);
pLuaVM.Push(isFile);
lf.Call();
---------------------------------------
LuaFunction lf = (LuaFunction)pLuaVM.GetFunction("executeScript");
Both times I get null for LuaFunction. I'm at a loss and any
assistance would be greatly appreciated.
Jason