本文整理匯總了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);
}