本文整理汇总了C#中NLua.Lua类的典型用法代码示例。如果您正苦于以下问题:C# Lua类的具体用法?C# Lua怎么用?C# Lua使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lua类属于NLua命名空间,在下文中一共展示了Lua类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScriptManager
public ScriptManager()
{
_scriptQueue = new Queue<Tuple<string, Entity, string>>();
_lua = new Lua();
SandboxVM();
RegisterScriptMethods();
}
示例2: LuaScriptContext
public LuaScriptContext()
{
Log.Write("debug", "Creating Lua script context");
Lua = new Lua();
Lua.HookException += OnLuaException;
functionCache = new Cache<string, LuaFunction>(Lua.GetFunction);
}
示例3: 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();
}
示例4: Spell
public Spell(XmlNode xml, Lua lua)
: base()
{
Name = xml.SelectSingleNode("name").InnerText;
Desc = xml.SelectSingleNode("desc").InnerText;
Type = (AttackType)Enum.Parse(typeof(AttackType), xml.SelectSingleNode("type").InnerText);
Target = (BattleTarget)Enum.Parse(typeof(BattleTarget), xml.SelectSingleNode("target").InnerText);
XmlNode targetsFirstNode = xml.SelectSingleNode("targetEnemiesFirst");
TargetEnemiesFirst = targetsFirstNode == null ? true : Boolean.Parse(targetsFirstNode.InnerText);
XmlNode costNode = xml.SelectSingleNode("cost");
MPCost = costNode == null ? 0 : Int32.Parse(costNode.InnerText);
XmlNode orderNode = xml.SelectSingleNode("order");
Order = orderNode == null ? 0 : Int32.Parse(orderNode.InnerText);
Elements = GetElements(xml.SelectNodes("elements/element")).ToArray();
Statuses = GetStatusChanges(xml.SelectNodes("statusChange")).ToArray();
Power = Int32.Parse(xml.SelectSingleNode("power").InnerText);
Hitp = Int32.Parse(xml.SelectSingleNode("hitp").InnerText);
XmlNode hitsNode = xml.SelectSingleNode("hits");
Hits = hitsNode == null ? 1 : Int32.Parse(hitsNode.InnerText);
DamageFormula = GetFormula(xml.SelectSingleNode("formula"), lua);
HitFormula = GetHitFormula(xml.SelectSingleNode("hitFormula"), lua);
}
示例5: 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;
}
示例6: TestBinaryLoadFile
public void TestBinaryLoadFile ()
{
using (Lua lua = new Lua ()) {
lua.LoadCLRPackage ();
if (IntPtr.Size == 4)
lua.DoFile ("test_32.luac");
else
lua.DoFile ("test_64.luac");
int width = (int)(double)lua ["width"];
int height = (int)(double)lua ["height"];
string message = (string)lua ["message"];
int color_g = (int)(double)lua ["color.g"];
LuaFunction func = (LuaFunction)lua ["func"];
object[] res = func.Call (12, 34);
int x = (int)(double)res [0];
int y = (int)(double)res [1];
//function func(x,y)
// return x,x+y
//end
Assert.AreEqual (100, width);
Assert.AreEqual (200, height);
Assert.AreEqual ("Hello World!", message);
Assert.AreEqual (20, color_g);
Assert.AreEqual (12, x);
Assert.AreEqual (46, y);
}
}
示例7: Start
void Start()
{
lua = new NLua.Lua();
lua.LoadCLRPackage();
var method = typeof(Debug).GetMethod("Log", new Type[] { typeof(object) });
lua.RegisterFunction("print", method);
}
示例8: 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;
}
示例9: ScriptComponent
public ScriptComponent()
{
Family = ComponentFamily.Script;
lua = new Lua();
lua.LoadCLRPackage();
}
示例10: 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;
}
示例11: RegisterNLuaBox
public static void RegisterNLuaBox(Lua context)
{
context.RegisterLuaDelegateType (typeof (EventHandler<EventArgs>), typeof (LuaEventArgsHandler));
context.RegisterLuaDelegateType (typeof (EventHandler), typeof (LuaEventArgsHandler));
context.RegisterLuaDelegateType (typeof (EventHandler<UIButtonEventArgs>), typeof (LuaButtonEventArgsHandler));
context.RegisterLuaClassType (typeof (UIViewController), typeof (NLuaBoxUIViewControllerBinder));
}
示例12: Main
static void Main(string [] args)
{
using (var l = new Lua ()) {
Action c = () => { Console.WriteLine ("Ola"); };
l ["d"] = c;
l.DoString (" d () ");
}
}
示例13: BuildingManager
static BuildingManager()
{
lua = new Lua();
InitPaths = new Dictionary<string,string>();
Buildings = new List<Building>();
//Scan();
//lua.
}
示例14: VsErcPackage
public VsErcPackage()
{
instance = this;
this.vsHelper = new VsHelper(this);
this.vsErcLogger = new VsErcLogger(this);
this.lua = new Lua();
this.vsErcBindings = new VsErcBindings(this, VsErcBindings.DefaultErcFilePath);
}
示例15: SetLog
public static void SetLog(Lua lua)
{
if (PrintFunction == null)
PrintFunction = new LuaNativeFunction(PrintWarning);
LuaLib.LuaPushStdCallCFunction(lua.LuaState, PrintFunction);
LuaLib.LuaSetGlobal(lua.LuaState, "log");
}