本文整理汇总了C#中NLua.Lua.DoString方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.DoString方法的具体用法?C# Lua.DoString怎么用?C# Lua.DoString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLua.Lua
的用法示例。
在下文中一共展示了Lua.DoString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitEditorState
private static void InitEditorState(Lua state)
{
state.LoadCLRPackage();
string resName = "WorldSmith.Scripts.WorldsmithImports.lua";
Assembly asm = Assembly.GetExecutingAssembly();
using (System.IO.Stream s = asm.GetManifestResourceStream(resName))
using (System.IO.StreamReader reader = new System.IO.StreamReader(s))
{
string data = reader.ReadToEnd();
state.DoString(data, resName);
}
state["Units"] = DotaData.AllUnits;
state["Heroes"] = DotaData.AllHeroes;
state["Abilities"] = DotaData.AllAbilities;
state["Items"] = DotaData.DefaultItems;
state["Events"] = DotaData.Events;
//Bind the DataClass enum
state.DoString("DataClass = {}");
state["DataClass.Default"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Default;
state["DataClass.Override"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Override;
state["DataClass.Custom"] = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom;
}
示例2: Item
public Item(XmlNode node, Lua lua)
: this()
{
Name = node.SelectSingleNode("name").InnerText;
Description = node.SelectSingleNode("desc").InnerText;
XmlNode field = node.SelectSingleNode("field");
if (field != null)
{
FieldUsage = new FieldUsageRecord();
FieldUsage.Target = (FieldTarget)Enum.Parse(typeof(FieldTarget), field.SelectSingleNode("@target").Value);
char targetParameterName = Char.ToLower(FieldUsage.Target.ToString()[0]);
string canUse = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("canUse").InnerText);
string use = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("use").InnerText);
try
{
FieldUsage.CanUse = (LuaFunction)lua.DoString(canUse).First();
FieldUsage.Use = (LuaFunction)lua.DoString(use).First();
}
catch (Exception e)
{
throw new ImplementationException("Error in item field scripts; id = " + ID, e);
}
}
XmlNode battle = node.SelectSingleNode("battle");
if (battle != null)
{
BattleUsage = new BattleUsageRecord();
BattleUsage.Target = (BattleTarget)Enum.Parse(typeof(BattleTarget), battle.SelectSingleNode("@target").Value);
XmlNode intendedForEnemiesNode = battle.SelectSingleNode("@intendedForEnemies");
if (intendedForEnemiesNode != null)
{
BattleUsage.IntendedForEnemies = Boolean.Parse(intendedForEnemiesNode.Value);
}
string use = String.Format("return function (s, t) {0} end", battle.SelectSingleNode("use").InnerText);
try
{
BattleUsage.Use = (LuaFunction)lua.DoString(use).First();
}
catch (Exception e)
{
throw new ImplementationException("Error in item battle scripts; id = " + ID, e);
}
}
}
示例3: Main
static void Main (string [] args)
{
using (var l = new Lua ()) {
l.LoadCLRPackage ();
l.DoString (" import ('ConsoleTest') ");
l.DoString (@"
Program.Method (1)
");
}
}
示例4: Main
static void Main (string [] args)
{
using (var l = new Lua ()) {
l.LoadCLRPackage ();
l.DoString (" import ('ConsoleTest', 'NLuaTest.Mock') ");
l.DoString (@"
e1 = Entity()
e2 = Entity ('Another world')
e3 = Entity (10)
");
}
}
示例5: Start
void Start () {
lua = new Lua();
// 加载定义脚本
lua.DoString(CommonLuaScript.text);
lua.DoString(BindLuaScript.text);
lua["gameObject"] = gameObject;
lua["transform"] = transform;
LuaFunction luaFunc = lua.GetFunction("test");
luaFunc.Call();
}
示例6: TestCLRPackage
public void TestCLRPackage ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString ("import ('NLuaTest', 'NLuaTest.Mock') ");
lua.DoString ("test = TestClass()");
lua.DoString ("test:setVal(3)");
object[] res = lua.DoString ("return test");
TestClass test = (TestClass)res [0];
Assert.AreEqual (3, test.testval);
}
}
示例7: TestUseNSUrl
public void TestUseNSUrl ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
lua.DoString ("import ('monotouch', 'MonoTouch.Foundation') ");
lua.DoString ("testURL = NSUrl('http://nlua.org/?query=param')");
lua.DoString ("host = testURL.Host");
object res = lua["host"];
string host = (string)res;
Assert.AreEqual ("nlua.org", host);
}
}
示例8: Button_Run_Click
private void Button_Run_Click(object sender, RoutedEventArgs e)
{
Lua lua = new Lua();
lua["Robot"] = _luaProxyRobot;
try
{
lua.DoString(@"import = function () end");
lua.DoString(TextBox_Script.Text);
}
catch (Exception ex)
{
AppendToLog("Exception: \n" + ex.ToString());
}
}
示例9: TestNullable
public void TestNullable ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("val=test.NullableBool");
Assert.AreEqual (null, (object)lua ["val"]);
lua.DoString ("test.NullableBool = true");
lua.DoString ("val=test.NullableBool");
Assert.AreEqual (true, (bool)lua ["val"]);
}
}
示例10: LuaDelegateValueTypesReturnReferenceType
public void LuaDelegateValueTypesReturnReferenceType ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return TestClass(x+y); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate4(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
示例11: executeCommand
/// <summary>
/// Try to execute a Lua command given in a string
/// </summary>
/// <param name="luaCommand"></param>
public static bool executeCommand(string luaCommand)
{
Lua lua = new Lua();
lua.LoadCLRPackage();
lua.DoString(@" import ('TextRPG', 'TextRPG')
import ('System') ");
try {
lua.DoString(luaCommand);
return true;
}
catch (Exception e)
{
return false;
}
}
示例12: ThrowException
public void ThrowException ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('mscorlib')");
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("err,errMsg=pcall(test.exceptionMethod,test)");
bool err = (bool)lua ["err"];
Exception errMsg = (Exception)lua ["errMsg"];
Assert.False (err);
Assert.NotNull (errMsg.InnerException);
Assert.AreEqual ("exception test", errMsg.InnerException.Message);
}
}
示例13: Init
public void Init()
{
if (IsInitialized)
throw new InvalidOperationException("Already Initialized!");
if (_state != null) _state.Dispose();
_state = new Lua();
_state.LoadCLRPackage();
_state.DoString(@"luanet.load_assembly('WGestures.Core');
luanet.load_assembly('WindowsInput');
luanet.load_assembly('WGestures.Common');
GestureModifier=luanet.import_type('WGestures.Core.GestureModifier');
VK=luanet.import_type('WindowsInput.Native.VirtualKeyCode');
Native=luanet.import_type('WGestures.Common.OsSpecific.Windows.Native');
", "_init");
_state["Input"] = Sim.Simulator;
_state.RegisterFunction("ReportStatus", this, typeof(ScriptCommand).GetMethod("OnReportStatus"));
if(InitScript != null)
{
DoString(InitScript, "Init");
}
IsInitialized = true;
}
示例14: Main
private static void Main()
{
Console.Title = "NLua Test Environment";
object x = 3;
double y = (double)(int)x;
string script = "function add(a, b) return a + b, a, b; end\n" +
"local function sub(a, b) return a - b; end\n" +
"local function mul(a, b) return a * b; end\n" +
"local function div(a, b) return a / b; end\n" +
"print(\"Adding 1 and 5 gives us \" .. add(1, 5));\n" +
"print(\"Subtracting 8 and 2 gives us \" .. sub(8, 2));\n" +
"print(\"Multiplying 32 and 1024 gives us \" .. mul(32, 1024));\n" +
"print(\"Dividing 8 and 2 gives us \" .. div(8, 2));\n";
using (dynamic lua = new Lua())
{
lua.LoadStandardLibrary(LuaStandardLibraries.Basic);
lua.DoString("print(\"This confirms the Lua environment has loaded the basic standard library.\\nThe Lua environment is operational.\");");
lua.DoFile("TestScript.lua");
lua.v = "test";
object[] table = lua.x;
}
Console.ReadLine();
}
示例15: Awakening
public bool Awakening()
{
spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle;
spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon;
env = new NLua.Lua();
env.LoadCLRPackage();
env["this"] = this; // Give the script access to the gameobject.
env["transform"] = transform;
env["gameObject"] = gameObject;
env["enabled"] = enabled;
env["useAPI"] = new Action(UseAPI);
env["disableAPI"] = new Action(DisableAPI);
if (Settings.useAPI)
{
Besiege.SetUp();
env["besiege"] = Besiege._besiege;
}
try
{
env.DoString(source);
}
catch (NLua.Exceptions.LuaException e)
{
Debug.LogError(FormatException(e), context: gameObject);
return false;
}
Call("Awake");
return true;
}