本文整理汇总了C#中ILuaState.PCall方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.PCall方法的具体用法?C# ILuaState.PCall怎么用?C# ILuaState.PCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.PCall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeTable
/// <summary>
/// 将Table序列化成为字符串写入文件
/// </summary>
public string SerializeTable(ILuaState _fileLua, int index)
{
//获取LibCore中_SerializeTable函数,然后串行化table, 以后要重写,从而不依赖LibCore(因为有在非运行状态下获取内容)
if (_fileLua.Type(index) != LuaType.LUA_TTABLE)
{
Debug.LogWarning("LuaExport:SerializeTable param must a table.. please check");
return "";
}
int dwStackIndex = _fileLua.GetTop();
_fileLua.PushValue(index);
_fileLua.GetGlobal("_SerializeTable");
_fileLua.Insert(-2);
_fileLua.PushBoolean(false);
if (_fileLua.PCall(2, 1, 0) != 0)
{
Debug.LogWarning(_fileLua.ToString(-1) + " in SerializeTable");
_fileLua.Pop(-1);
return "";
}
string szResult = _fileLua.ToString(-1);
//Debug.Log(m_szResult);
_fileLua.Pop(1);
if (dwStackIndex != _fileLua.GetTop())
Debug.LogWarning("LuaExport:SerializeTable stack Exception:start=" + dwStackIndex + " end=" + _fileLua.GetTop());
return szResult;
}
示例2: docall
/*
** Interface to 'lua_pcall', which sets appropriate message function
** and C-signal handler. Used to run all chunks.
*/
static LuaStatus docall(ILuaState L, int narg, int nres)
{
LuaStatus status = 0;
int base_ = L.GetTop() - narg; /* function index */
L.PushFunction(msghandler); /* push message handler */
L.Insert(base_); /* put it under function and args */
globalL = L; /* to be available to 'laction' */
Console.CancelKeyPress += Console_CancelKeyPress;
//signal(SIGINT, laction); /* set C-signal handler */
status = L.PCall(narg, nres, base_);
//signal(SIGINT, SIG_DFL); /* reset C-signal handler */
Console.CancelKeyPress -= Console_CancelKeyPress;
L.Remove(base_); /* remove message handler from the stack */
return status;
}
示例3: l_print
/*
** Prints (calling the Lua 'print' function) any values on the stack
*/
static void l_print(ILuaState L)
{
int n = L.GetTop();
if (n > 0)
{ /* any result to be printed? */
L.CheckStack(L.MinStack, "too many results to print");
L.GetGlobal("print");
L.Insert(1);
if (L.PCall(n, 0, 0) != LuaStatus.OK)
l_message(L, progname, L.PushFString("error calling 'print' (%s)", L.ToString(-1)));
}
}
示例4: Lua_pcall
/// <summary>
/// 为啥加这个这是个神奇的问题
/// </summary>
/// <param name="lua"></param>
/// <returns></returns>
private int Lua_pcall(ILuaState lua)
{
if (lua.Type(1) != LuaType.LUA_TFUNCTION)
{
lua.PushBoolean(false);
//lua.PushString(lua.PrintLuaStack("pcall failed parm 1 function. excepted."));
return 2;
}
int nCount = lua.GetTop();
lua.PushValue(1);
for (int i = 2; i <= nCount; ++i)
{
lua.PushValue(i);
}
if (lua.PCall(nCount - 1,0,0) != 0)
{
lua.PushBoolean(false);
lua.Insert(-2);
return 2;
}
lua.PushBoolean(true);
return 1;
}