public static LuaTable RequireAndInstanceWith(LuaEnv luaEnv, string scriptPath, SystemObject[] operateParams) { if (string.IsNullOrEmpty(scriptPath)) { LuaLogger.Error(LOG_TAG, "the path of script is empty"); return(null); } if (luaEnv == null || !luaEnv.IsValid()) { LuaLogger.Error(LOG_TAG, "the env of lua is invalid"); return(null); } SystemObject[] values = luaEnv.DoString($"return require('{scriptPath}')"); if (values != null && values.Length > 0) { LuaTable classTable = values[0] as LuaTable; if (classTable != null) { LuaFunction ctrFunc = classTable.Get <LuaFunction>("__call"); if (ctrFunc != null) { return(ctrFunc.Func <LuaTable>(operateParams)); } } } LuaLogger.Error(LOG_TAG, "the value is null"); return(null); }
public static bool Require(LuaEnv luaEnv, string scriptPath) { if (string.IsNullOrEmpty(scriptPath)) { LuaLogger.Error(LOG_TAG, "the path of script is empty"); return(false); } if (luaEnv == null || !luaEnv.IsValid()) { LuaLogger.Error(LOG_TAG, "the env of lua is invalid"); return(false); } luaEnv.DoString($"require('{scriptPath}')"); return(true); }
public static LuaTable RequireAndGet(LuaEnv luaEnv, string scriptPath) { if (string.IsNullOrEmpty(scriptPath)) { LuaLogger.Error(LOG_TAG, "the path of script is empty"); return(null); } if (luaEnv == null || !luaEnv.IsValid()) { LuaLogger.Error(LOG_TAG, "the env of lua is invalid"); return(null); } string name = GetScriptName(scriptPath); LuaTable table = luaEnv.Global.Get <LuaTable>(name); if (table == null) { luaEnv.DoString($"require(\"{scriptPath}\")"); table = luaEnv.Global.Get <LuaTable>(name); } return(table); }
public static LuaTable RequireAndInstance(LuaEnv luaEnv, string scriptPath) { if (string.IsNullOrEmpty(scriptPath)) { LuaLogger.Error(LOG_TAG, "the path of script is empty"); return(null); } if (luaEnv == null || !luaEnv.IsValid()) { LuaLogger.Error(LOG_TAG, "the env of lua is invalid"); return(null); } SystemObject[] values = luaEnv.DoString($"local data = require('{scriptPath}') return data()"); if (values != null && values.Length > 0) { return(values[0] as LuaTable); } else { LuaLogger.Error(LOG_TAG, "the value is null"); return(null); } }