public bool RegisterLuaFunction(LuaManager.LuaFunction func, string luaFuncName) { if (m_luaState == IntPtr.Zero) { return(false); } // call the lua_register API function to register a .Net function with // the name luaFuncName and a function pointer func // the function pointer is defined using the delegate shown earlier // when making the correct Lua function signature for .Net functions try { LuaManager.lua_register(m_luaState, luaFuncName, func); } catch (Exception ex) { DoW2Bridge.TimeStampedTrace("LUA REGISTER FAILED!"); DoW2Bridge.TimeStampedTrace(ex.Message); m_refs.Clear(); m_luaState = IntPtr.Zero; return(false); } // make sure the delegate callback is not collected by the garbage collector before // unmanaged code has called back m_refs.Add(func); return(true); }
public static void Init() { DoW2Bridge.TimeStampedTrace("CopeDebug - Establishing Cope's Forward Operations Base!"); s_currentProcess = Process.GetCurrentProcess(); CommandProcessor.Processor = new GenericMethod <string, string>(CmdProcessor); s_cmdHandlers.Add("PropertyGroupManager_ReloadGroup", PropertyGroupManagerReloadPg); s_cmdHandlers.Add("PropertyGroupManager_GetBasePath", PropertyGroupManagerGetBasePath); s_cmdHandlers.Add("PropertyGroupManager_GetGroup", PropertyGroupManagerGetGroup); s_cmdHandlers.Add("print", Print); DoW2Bridge.TimeStampedTrace("CopeDebug - Setup finished!"); //DoW2Bridge.LuaInit(); }
static string Print(string[] args) { if (args.Length == 0) { return("print(string message) expects one parameter, no parameters received!"); } if (!IsString(args[0])) { return("print(string message) expects one parameter of type STRING, wrong type!"); } DoW2Bridge.TimeStampedTrace(ParseString(args[0])); return(null); }
static string PropertyGroupManagerReloadPg(string[] args) { if (args.Length == 0) { return("PropertyGroupManager_ReloadGroup(string propertyGroup) expects one parameter, no parameters received!"); } if (!IsString(args[0])) { return("PropertyGroupManager_ReloadGroup(string propertyGroup) expects one parameter of type STRING, wrong type!"); } string arg0 = ParseString(args[0]); IntPtr propertyGroupManager; try { propertyGroupManager = DoW2Bridge.PropertyGroupManager_Instance(); } catch (Exception ex) { return("PropertyGroupManager_Instance failed: " + ex.Message); } if (propertyGroupManager == null) { return("PropertyGroupManager_Instance failed!"); } IntPtr pg; try { pg = DoW2Bridge.PropertyGroupManager_ReloadPropertyGroup(propertyGroupManager, arg0); } catch (Exception ex) { return("PropertyGroupManager_ReloadPropertyGroup failed: " + ex.Message); } if (pg == null) { return("PropertyGroupManager_ReloadPropertyGroup failed!"); } DoW2Bridge.TimeStampedTrace("CopeDebug - " + arg0 + " reloaded"); return("PropertyGroup " + arg0 + " reloaded"); }
static string PropertyGroupManagerGetGroup(string[] args) { if (args.Length == 0) { return("PropertyGroupManager_GetGroup(string propertyGroup) expects one parameter, no parameters received!"); } if (!IsString(args[0])) { return("PropertyGroupManager_GetGroup(string propertyGroup) expects one parameter of type STRING, wrong type!"); } IntPtr propertyGroupManager; try { propertyGroupManager = DoW2Bridge.PropertyGroupManager_Instance(); } catch (Exception ex) { return("PropertyGroupManager_Instance failed: " + ex.Message); } if (propertyGroupManager == null) { return("PropertyGroupManager_Instance failed!"); } IntPtr pg; try { pg = DoW2Bridge.PropertyGroupManager_GetGroup(propertyGroupManager, ParseString(args[0])); } catch (Exception ex) { return("PropertyGroupManager_GetGroup failed: " + ex.Message); } if (pg == null) { return("PropertyGroupManager_GetGroup failed!"); } return("GetGroup succeeded, address: " + pg); }
static string PropertyGroupManagerGetBasePath(string[] args) { return(DoW2Bridge.PropertyGroupManagerGetBasePath()); }