本文整理汇总了C#中System.Script.LoadString方法的典型用法代码示例。如果您正苦于以下问题:C# Script.LoadString方法的具体用法?C# Script.LoadString怎么用?C# Script.LoadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Script
的用法示例。
在下文中一共展示了Script.LoadString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Script_RunString
private DynValue Script_RunString(string script)
{
Script s1 = new Script();
DynValue v1 = s1.LoadString(script);
using (MemoryStream ms = new MemoryStream())
{
s1.Dump(v1, ms);
ms.Seek(0, SeekOrigin.Begin);
Script s2 = new Script();
DynValue func = s2.LoadStream(ms);
return func.Function.Call();
}
}
示例2: PrintTest2
public void PrintTest2()
{
string script = @"
t = {};
m = {};
function m.__tostring()
return 'ciao';
end
setmetatable(t, m);
print(t, 1);
";
string printed = null;
Script S = new Script();
DynValue main = S.LoadString(script);
S.Options.DebugPrint = s =>
{
printed = s;
};
S.Call(main);
Assert.AreEqual("ciao\t1", printed);
}
示例3: ParsingTest
public void ParsingTest()
{
Script S = new Script(CoreModules.None);
DynValue res = S.LoadString(@"
t = {'a', 'b', 'c', ['d'] = 'f', ['e'] = 5, [65] = true, [true] = false}
function myFunc()
return 'one', 'two'
end
print('Table Test 1:')
for k,v in pairs(t) do
print(tostring(k) .. ' / ' .. tostring(v))
end
print('Table Test 2:')
for X,X in pairs(t) do
print(tostring(X) .. ' / ' .. tostring(X))
end
print('Function Test 1:')
v1,v2 = myFunc()
print(v1)
print(v2)
print('Function Test 2:')
v,v = myFunc()
print(v)
print(v)
");
}
示例4: PrintTest1
public void PrintTest1()
{
string script = @"
print('ciao', 1);
";
string printed = null;
Script S = new Script();
DynValue main = S.LoadString(script);
S.Options.DebugPrint = s =>
{
printed = s;
};
S.Call(main);
Assert.AreEqual("ciao\t1", printed);
}