public void Init(string strAPIInfoFile) { m_strCode = ""; m_strAPIInfoFile = strAPIInfoFile; m_lua = new Lua(); m_lua.DoFile(m_strAPIInfoFile); m_luatable = m_lua.GetTable("APIInfo"); m_nClassCount = m_luatable.Keys.Count; m_strClass = new string[m_nClassCount]; m_strClassInCode = new string[m_nClassCount]; m_strIniFileName = Application.StartupPath + "\\Plugins\\LuaCheck\\API.temp.lua"; m_lua1 = new Lua(); m_lua1.DoFile(m_strIniFileName); int n = 0; foreach (string str in m_luatable.Keys) { m_strClass[n] = (string)(((LuaTable)m_luatable[str])["Name"]); n++; } //object ob; //foreach (ob in m_luatable) //{ // strClass[] = ((LuaTable)ob)["Name"]; //} //object ob = m_luatable["1"]; //object ob1 = ((LuaTable)ob)["Name"]; }
public void loadGameData(ref Lua lua, string gameDataFilePath) { //string lineRead; //char[] tokenizer = {':', '\"', '\'' }; //StreamReader SRead = new StreamReader(gameDataFilePath, System.Text.Encoding.UTF8); //while ((lineRead = SRead.ReadLine()) != null) //{ // readLinetoData(ref lua, lineRead, tokenizer); //} //SRead.Close(); try { XmlDocument xmldata = new XmlDocument(); xmldata.Load(gameDataFilePath); XmlElement root = xmldata.DocumentElement; XmlNodeList nodes = root.ChildNodes; foreach (XmlNode node in nodes) { lua[node.Name] = node.InnerText; } } catch(IOException e) { Console.WriteLine(e); } Console.WriteLine("Data Successfully Loaded!"); }
public LuaWinform(Lua ownerThread) { InitializeComponent(); OwnerThread = ownerThread; StartPosition = FormStartPosition.CenterParent; Closing += (o, e) => CloseThis(); }
static void Main2() { Lua L = new Lua(); // L.DoString("UnityEngine = luanet.UnityEngine"); // L.DoString("print(UnityEngine)"); // L.DoString("cubetype = UnityEngine.PrimitiveType.Cube"); // L.DoString("print(cubetype)"); // L.DoString("gotype = UnityEngine.GameObject"); // L.DoString("print(gotype)"); // L.DoString("CP = gotype.CreatePrimitive"); // L.DoString("print(CP)"); // L.DoString("cube2 = UnityEngine.GameObject.CP2()"); // L.DoString("print(cube2)"); // L.DoString("cube = CP(cubetype)"); // L.DoString("cube = luanet.UnityEngine.GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)"); L.DoString("luanet.import_type(UnityEngine.GameObject)()"); L.DoString("luanet.UnityEngine.GameObject.CP2()"); while (true) { L.DoString("t = UnityEngine.Time.realtimeSinceStartup"); L.DoString("q = UnityEngine.Quaternion.AngleAxis(t*50, UnityEngine.Vector3.up)"); L.DoString("cube.transform.rotation = q"); System.Threading.Thread.Sleep(1); } }
public ObjectTranslator(Lua interpreter,IntPtr luaState) { this.interpreter=interpreter; typeChecker=new CheckType(this); metaFunctions=new MetaFunctions(this); objects=new ArrayList(); assemblies=new ArrayList(); importTypeFunction=new LuaCSFunction(this.importType); importType__indexFunction=new LuaCSFunction(this.importType__index); loadAssemblyFunction=new LuaCSFunction(this.loadAssembly); loadAssemblyFromFunction=new LuaCSFunction(this.loadAssemblyFrom); registerTableFunction=new LuaCSFunction(this.registerTable); unregisterTableFunction=new LuaCSFunction(this.unregisterTable); getMethodSigFunction=new LuaCSFunction(this.getMethodSignature); getConstructorSigFunction=new LuaCSFunction(this.getConstructorSignature); createLuaObjectList(luaState); createIndexingMetaFunction(luaState); createBaseClassMetatable(luaState); createClassMetatable(luaState); createFunctionMetatable(luaState); setGlobalFunctions(luaState); LuaDLL.lua_dostring(luaState, "load_assembly('mscorlib')"); }
public void Register(Lua lua) { lua.RegisterFunction("game.getWidth", this, this.GetType().GetMethod("GetWindowWidth")); lua.RegisterFunction("game.getHeight", this, this.GetType().GetMethod("GetWindowHeight")); lua.RegisterFunction("game.getCenter", this, this.GetType().GetMethod("GetWindowCenter")); lua.RegisterFunction("gui.registerMenu", this, this.GetType().GetMethod("RegisterMenu")); }
static void Main(string[] args) { using (var lua = new Lua()) { lua.DoFile("Apollo.lua"); var luaUnit = @"C:/git/luaunit"; var addonDir = "TrackMaster"; var addonPath = Path.Combine(Environment.GetEnvironmentVariable("appdata"), @"NCSOFT\Wildstar\Addons\" + addonDir + @"\"); lua.DoString(string.Format("package.path = package.path .. ';{0}/?.lua;{1}/?.lua'", luaUnit, addonPath.Replace('\\', '/'))); var toc = XDocument.Load(Path.Combine(addonPath, "toc.xml")); foreach (var script in toc.Element("Addon").Elements("Script")) { lua.DoFile(Path.Combine(addonPath, script.Attribute("Name").Value)); } foreach (var testFiles in Directory.GetFiles(Path.Combine(addonPath, "Tests"))) { Console.WriteLine("Loading File: " + testFiles); lua.DoFile(testFiles); } try { lua.DoString("require('luaunit'):run()"); } catch (LuaException ex) { Console.WriteLine("Execution Error: " + ex.ToString()); } //Console.ReadLine(); } }
private static Lua ConfigureLua(PacketReader PacketReader, StreamWriter outputWriter) { Lua LuaInterpreter = new Lua(); LuaInterpreter.RegisterFunction("readByte", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadByte" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readShort", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadShort" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readInt", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadInt" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readLong", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadLong" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readString", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadString" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readSlot", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadSlot" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readMob", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadMobMetadata" && m.GetParameters().Length == 0 ).First()); LuaInterpreter.RegisterFunction("readBytes", PacketReader, typeof(PacketReader).GetMethod("ReadBytes")); LuaInterpreter.RegisterFunction("readBoolean", PacketReader, typeof(PacketReader).GetMethods().Where( m => m.Name == "ReadBoolean" && m.GetParameters().Length == 0 ).First()); return LuaInterpreter; }
internal void SetupScope(Lua lua, Quest q) { foreach(ConstructorInfo constructor in registeredTriggers) { lua.RegisterFunction(constructor.DeclaringType.Name, q, constructor); } }
public void OnActivate() { // Create the lua state luastate = new Lua(); // Setup hooks dctHooks = new Dictionary<string, List<LuaFunction>>(); // Bind functions BindFunction("print", "print"); luastate.NewTable("hook"); BindFunction("hook.Add", "hook_Add"); luastate.NewTable("library"); BindFunction("library.AddWeapon", "library_AddWeapon"); BindFunction("library.AddSystem", "library_AddSystem"); BindFunction("library.AddRace", "library_AddRace"); BindFunction("library.AddShipGenerator", "library_AddShipGenerator"); BindFunction("library.AddSectorMapGenerator", "library_AddSectorMapGenerator"); BindFunction("library.GetWeapon", "library_GetWeapon"); BindFunction("library.GetSystem", "library_GetSystem"); BindFunction("library.GetRace", "library_GetRace"); BindFunction("library.GetShip", "library_GetShipGenerator"); BindFunction("library.GetSectorMapGenerator", "library_GetSectorMapGenerator"); BindFunction("library.CreateAnimation", "library_CreateAnimation"); luastate.NewTable("ships"); BindFunction("ships.NewDoor", "ships_NewDoor"); // Is there any way to call the constructor directly from lua code? // Load lua files if (!Directory.Exists("lua")) Directory.CreateDirectory("lua"); foreach (string name in Directory.GetFiles("lua")) luastate.DoFile("lua/" + name); }
public LuaEngine(IEnumerable<IGlobalProvider> globalProviders, IScriptParser scriptParser, IPluginInvoker pluginInvoker) { this.globalProviders = globalProviders; this.scriptParser = scriptParser; this.pluginInvoker = pluginInvoker; luaWorker = new BackgroundWorker(); lua = new Lua(); }
public static void ClearCurrentThread() { lock (ThreadMutex) { CurrentHostThread = null; CurrentThread = null; } }
public static void ReleaseLua(Lua lua) { lock (m_queue) { m_queue.Enqueue(lua); Console.WriteLine("lua queue count:{0}", m_queue.Count); } }
public static LuaSandbox CreateSandbox(Lua thread, string initialDirectory) { var sandbox = new LuaSandbox(); SandboxForThread.Add(thread, sandbox); sandbox.SetSandboxCurrentDirectory(initialDirectory); sandbox.SetLogger(DefaultLogger); return sandbox; }
public LuaJIT() { //this.instance = new lua_StatePtr(); //this.ud = new size_t_p(0); //this.instance = Luajit.lua_newstate(normal_lua_Alloc, ud); this.lua_instance = new Lua(); //lua_instance. }
public void CallExitEvent(Lua thread) { var exitCallbacks = _luaFunctions.Where(x => x.Lua == thread && x.Event == "OnExit"); foreach (var exitCallback in exitCallbacks) { exitCallback.Call(); } }
public lau(XDevkit.IXboxConsole Newxbc) { xbc = Newxbc; pLuaVM = new Lua(); pLuaFuncs = new Hashtable(); pLuaPackages = new Hashtable(); registerLuaFunctions(null, this, null); }
public MemoryLuaLibrary(Lua lua) : base(lua) { if (MemoryDomainCore != null) { _currentMemoryDomain = MemoryDomainCore.MainMemory; } }
/// <summary> /// /// </summary> public LuaInterfaceProxy() { _lua = new LuaInterface.Lua(); if (_lua == null) { throw new LuaException(Resources.ERR_UNABLE_INITIALIZE); } }
public MemoryLuaLibrary(Lua lua, Action<string> logOutputCallback) : base(lua, logOutputCallback) { if (MemoryDomainCore != null) { _currentMemoryDomain = MemoryDomainCore.MainMemory; } }
public void Dispose() { if (lua != null) { lua.Close(); //no dispose(), this gives a access-violation... lua = null; } }
/// <summary> /// /// </summary> public LuaInterfaceProxy() { _lua = new LuaInterface.Lua(); if (_lua == null) { throw new LuaException("Unable to initialize the Lua Virtual Machine"); } }
static void Main(string[] args) { Lua lua = new Lua(); lua["x"] = 3; lua.DoString("y=x"); Console.WriteLine("y={0}", lua["y"]); { lua.DoString("luanet.load_assembly('SimpleTest')"); lua.DoString("Foo = luanet.import_type('SimpleTest.Foo')"); lua.DoString("method = luanet.get_method_bysig(Foo, 'OutMethod', 'SimpleTest.Foo', 'out SimpleTest.Bar')"); Console.WriteLine(lua["method"]); } { object[] retVals = lua.DoString("return 1,'hello'"); Console.WriteLine("{0},{1}", retVals[0], retVals[1]); } { KopiLua.Lua.lua_pushcfunction(lua.luaState, Func); KopiLua.Lua.lua_setglobal(lua.luaState, "func"); Console.WriteLine("registered 'func'"); double result = (double)lua.DoString("return func(1,2,3)")[0]; Console.WriteLine("{0}", result); } { Bar bar = new Bar(); bar.x = 2; lua["bar"] = bar; Console.WriteLine("'bar' registered"); object o = lua["bar"]; Console.WriteLine("'bar' read back as {0}", o); Console.WriteLine(o == bar ? "same" : "different"); Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]); double result = (double)lua.DoString("return bar.x")[0]; Console.WriteLine("lua says bar.x = {0}", result); lua.DoString("bar.x = 4"); Console.WriteLine("now bar.x = {0}", bar.x); } { Foo foo = new Foo(); lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply")); Console.WriteLine("registered 'multiply'"); double result = (double)lua.DoString("return multiply(3)")[0]; Console.WriteLine("{0}", result); } Console.WriteLine("Finished, press Enter to quit"); Console.ReadLine(); }
public static LuaTable GetTable(this LuaInterface.Lua lua, string tableName) { if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException(nameof(tableName)); } return(lua[tableName] as LuaTable); }
public void Register(Lua lua) { lua.RegisterFunction("game.exit", this, this.GetType().GetMethod("Exit")); lua.RegisterFunction("game.setState", this, this.GetType().GetMethod("SetState")); lua.RegisterFunction("game.addState", this, this.GetType().GetMethod("AddState")); lua.RegisterFunction("game.getXnaGame", this, this.GetType().GetMethod("GetXnaGame")); lua.RegisterFunction("game.getGraphicsDevice", this, this.GetType().GetMethod("GetGraphicsDevice")); lua.RegisterFunction("game.startGame", this, GetType().GetMethod("StartGame")); }
public LuaManager() : base(ROClient.Singleton) { _luaparser = new LuaInterface.Lua(); LoadAccessory(); LoadRobe(); LoadNpcIdentity(); }
public static void Initialize() { LuaVm = new Lua(); RegisterMethods(); GuiManager.Initialize(); ScriptManager.CreateFolders(); }
/// <summary> /// 初始化数据 /// </summary> private void Init() { string luaFile = Path.Combine(Application.StartupPath, "ConfigEdit.lua"); FileInfo fi = new FileInfo(luaFile); if(fi.Exists) { lua = new Lua(); lua.DoFile(luaFile); } }
public GUIAddon(string a_filePath) { m_lua = new Lua(); ((GameState)Game.getInstance().getCurrentState()).getGUI().registerFunctions(m_lua); m_lua.DoFile(a_filePath); m_onLoad = m_lua.GetFunction("OnLoad"); m_onUpdate = m_lua.GetFunction("OnUpdate"); m_onDraw = m_lua.GetFunction("OnDraw"); }
public static void SetCurrentThread(Lua luaThread) { lock (ThreadMutex) { if (CurrentHostThread != null) throw new InvalidOperationException("Can't have lua running in two host threads at a time!"); CurrentHostThread = Thread.CurrentThread; CurrentThread = luaThread; } }
private Hashtable _packages = null; // Registered packages in the Lua virtual machine #endregion Fields #region Constructors /// <summary> /// Creates an object for interfacing with the Lua virtual machine. /// </summary> /// <param name="register">Whether to register the built-in functions.</param> public LuaVirtualMachine( bool register ) { _lua = new Lua(); _functions = new Hashtable(); _packages = new Hashtable(); // Register the built-in Lua functions if ( register ) RegisterLuaFunctions( this ); }
public GameConsole() { historique = ""; text = ""; onA = false; lua = LuaManager.LuaVM; MethodInfo mInfo = typeof(GameConsole).GetMethod("show"); LuaManager.registerLuaFunctions(this); }
//[STAThread] private static void Main(string[] args) { if (args.Length > 0) { // For attaching from the debugger // Thread.Sleep(20000); using (var lua = new LuaInterface.Lua()) { //lua.OpenLibs(); // steffenj: Lua 5.1.1 API change (all libs already opened in Lua constructor!) lua.NewTable("arg"); LuaTable argc = (LuaTable)lua["arg"]; argc[-1] = "LuaRunner"; argc[0] = args[0]; for (int i = 1; i < args.Length; i++) { argc[i] = args[i]; } argc["n"] = args.Length - 1; try { //Console.WriteLine("DoFile(" + args[0] + ");"); lua.DoFile(args[0]); } catch (Exception e) { // steffenj: BEGIN error message improved, output is now in decending order of importance (message, where, stacktrace) // limit size of strack traceback message to roughly 1 console screen height string trace = e.StackTrace; if (e.StackTrace.Length > 1300) { trace = e.StackTrace.Substring(0, 1300) + " [...] (traceback cut short)"; } Console.WriteLine(); Console.WriteLine(e.Message); Console.WriteLine(e.Source + " raised a " + e.GetType().ToString()); Console.WriteLine(trace); // wait for keypress if there is an error Console.ReadKey(); // steffenj: END error message improved } } } else { Console.WriteLine("LuaRunner -- runs Lua scripts with CLR access"); Console.WriteLine("Usage: luarunner <script.lua> [{<arg>}]"); } }
/// <summary> /// Unwaps an object comming from LuaInterface for use in DynamicLua. /// </summary> public static object UnWrapObject(object wrapped, Lua state, string name = null) { if (wrapped is LuaTable) return new DynamicLuaTable(wrapped as LuaTable, state, name); else if (wrapped is LuaFunction) return new DynamicLuaFunction(wrapped as LuaFunction); else if (wrapped is MulticastDelegate) return new DynamicLuaFunction(state.GetFunction(name)); else return wrapped; }
public Engine() { Lua = new LuaInterface.Lua(); Lua.NewTable("Client"); Lua.RegisterFunction("Client.ChangeState", this, this.GetType().GetMethod("ChangeClientState")); Lua.NewTable("NS"); Lua.NewTable("NS.Minor"); Lua.RegisterFunction("NS.Run", this, this.GetType().GetMethod("MethodName")); Lua.RegisterFunction("Print", this, this.GetType().GetMethod("Print")); Lua.RegisterFunction("print", this, this.GetType().GetMethod("Print")); }
internal bool Start(string initfile) { lua = new LuaInterface.Lua(); lua["server"] = server; lua.RegisterFunction("Is", this, this.GetType().GetMethod("Is")); if (!File.Exists(initfile)) { server.Log("Initfile '" + initfile + "' not found."); return(false); } try { lua.DoFile(initfile); } catch (Exception e) { Error(e); return(false); } return(true); }
static void Main(string[] args) { LuaInterface.Lua lua = new LuaInterface.Lua(); lua.DoString("print('12345')"); lua.DoFile("test.lua"); Console.WriteLine((string)lua["str"]);//访问lua中的变量 Program p = new Program(); lua.RegisterFunction("NormalMethod", p, p.GetType().GetMethod("Method")); lua.DoString("NormalMethod()"); lua.RegisterFunction("StaticMethod", null, typeof(Program).GetMethod("StaticMethod")); lua.DoString("StaticMethod()"); lua.DoFile("go.lua"); Console.ReadKey(); }
public LuaManagerKopi() { m_luaState = new LuaInterface.Lua(); }
public static LuaTable CreateTable(this LuaInterface.Lua lua) { lua.NewTable("my"); return(lua.GetTable("my")); }
public LuaInterpreter(SpiderView host) { this.host = host; this.lua = new LuaInterface.Lua(); this.lua.DoString(Properties.Resources.helperlua); // Add helper methods }