本文整理汇总了C#中LuaState.Load方法的典型用法代码示例。如果您正苦于以下问题:C# LuaState.Load方法的具体用法?C# LuaState.Load怎么用?C# LuaState.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaState
的用法示例。
在下文中一共展示了LuaState.Load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDump
public void TestDump()
{
LuaState L = null;
using (L = new LuaState())
{
String chunk = @"
a = 'Lua'
b = ' rocks'
c=a..b
return c..'!!'
";
Byte[] chunkBytes = Encoding.ASCII.GetBytes(chunk);
int curr = 0;
LuaReader loadChunk = (l, ud) => {
Byte[] res = null;
if (curr < chunkBytes.Length)
{
int c = Math.Min(chunkBytes.Length, chunkBytes.Length - curr);
res = new Byte[c];
Array.Copy(chunkBytes, curr, res, 0, c);
curr += c;
}
return res;
};
var st = L.Load(loadChunk, null, "main", null);
Assert.Equal(LuaStatus.OK, st);
List<Byte[]> dump = new List<byte[]>();
var r = L.Dump((l, b, ud) => {
dump.Add(b);
return 0;
}, null, 0);
Assert.Equal(0, r);
Byte[] dumpBytes = dump.SelectMany(d => d).ToArray();
Assert.Equal(199, dumpBytes.Length);
// Remove the function
L.Pop(1);
Assert.Equal(0, L.GetTop());
// Reload chunk compiled
chunkBytes = dumpBytes;
curr = 0;
st = L.Load(loadChunk, null, "main", "b");
Assert.Equal(LuaStatus.OK, st);
st = L.PCall(0, 1, 0);
Assert.Equal(LuaStatus.OK, st);
Assert.Equal("Lua rocks!!", L.ToString(-1));
}
}
示例2: TestLoad
public void TestLoad()
{
LuaState L = null;
using (L = new LuaState())
{
String chunk = @"
a = 'Lua'
b = ' rocks'
c=a..b
return c..'!!'
";
Byte[] chunkBytes = Encoding.ASCII.GetBytes(chunk);
int curr = 0;
var st = L.Load((l, ud) => {
Byte[] res = null;
if (curr < chunkBytes.Length)
{
int c = Math.Min(7, chunkBytes.Length - curr);
res = new Byte[c];
Array.Copy(chunkBytes, curr, res, 0, c);
curr += c;
}
return res;
}, null, "main", null);
Assert.Equal(LuaStatus.OK, st);
st = L.PCall(0, 1, 0);
Assert.Equal(LuaStatus.OK, st);
Assert.Equal("Lua rocks!!", L.ToString(-1));
}
}