本文整理汇总了C#中LuaTable.push方法的典型用法代码示例。如果您正苦于以下问题:C# LuaTable.push方法的具体用法?C# LuaTable.push怎么用?C# LuaTable.push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaTable
的用法示例。
在下文中一共展示了LuaTable.push方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoString
/// <summary>
/// Executes a Lua chnk and returns all the chunk's return values in an array.
/// </summary>
/// <param name="chunk">Chunk to execute</param>
/// <param name="chunkName">Name to associate with the chunk</param>
/// <returns></returns>
public object[] DoString(string chunk, string chunkName, LuaTable env)
{
int oldTop = LuaDLL.lua_gettop(L);
byte[] bt = Encoding.UTF8.GetBytes(chunk);
if (LuaDLL.luaL_loadbuffer(L, bt, bt.Length, chunkName) == 0)
{
if (env != null)
{
env.push(L);
//LuaDLL.lua_setfenv(L, -1);
LuaDLL.lua_setfenv(L, -2);
}
if (LuaDLL.lua_pcall(L, 0, -1, 0) == 0)
return translator.popValues(L, oldTop);
else
ThrowExceptionFromError(oldTop);
}
else
ThrowExceptionFromError(oldTop);
return null; // Never reached - keeps compiler happy
}
示例2: DoFile
/*
* Excutes a Lua file and returns all the chunk's return
* values in an array
*/
public object[] DoFile(string fileName, LuaTable env)
{
LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction);
int oldTop = LuaDLL.lua_gettop(L);
// Load with Unity3D resources
byte[] text = LuaStatic.Load(fileName);
if (text == null)
{
if (!fileName.Contains("mobdebug")) {
Debugger.LogError("Loader lua file failed: {0}", fileName);
}
LuaDLL.lua_pop(L, 1);
return null;
}
string luafile = Util.LuaPath(fileName);
//Encoding.UTF8.GetByteCount(text)
if (LuaDLL.luaL_loadbuffer(L, text, text.Length, luafile) == 0)
{
if (env != null)
{
env.push(L);
//LuaDLL.lua_setfenv(L, -1);
LuaDLL.lua_setfenv(L, -2);
}
if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0)
{
object[] results = translator.popValues(L, oldTop);
LuaDLL.lua_pop(L, 1);
return results;
}
else
{
ThrowExceptionFromError(oldTop);
LuaDLL.lua_pop(L, 1);
}
}
else
{
ThrowExceptionFromError(oldTop);
LuaDLL.lua_pop(L, 1);
}
return null; // Never reached - keeps compiler happy
}
示例3: LoadString
/// <summary>
///
/// </summary>
/// <param name="chunk"></param>
/// <param name="name"></param>
/// <returns></returns>
public LuaFunction LoadString(string chunk, string name, LuaTable env)
{
int oldTop = LuaDLL.lua_gettop(L);
byte[] bt = Encoding.UTF8.GetBytes(chunk);
if (LuaDLL.luaL_loadbuffer(L, bt, bt.Length, name) != 0)
ThrowExceptionFromError(oldTop);
if (env != null)
{
env.push(L);
LuaDLL.lua_setfenv(L, -2);
}
LuaFunction result = translator.getFunction(L, -1);
translator.popValues(L, oldTop);
return result;
}