--######################################################################################################### -- IRLUA PLUGIN HELPER FUNCTIONS By MicroByte --######################################################################################################### _ShowErrorEventContext=true-- set this to false to disable 'EventContext' display --######################################################################################################### -- Sets a Global error message in the runtime engine. IRLUA_PLUGIN_SetGlobalErrorMessage = function(nCode, sMessage) if _tblErrorMessages[nCode] then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("Error code "..nCode.." already in use, please use another.\r\n\r\nEventContext: "..sEventContext,2) else error("Error code "..nCode.." already in use, please use another.",2) end else _tblErrorMessages[nCode]=sMessage end end --######################################################################################################### -- Checks the number of arguments in the table nd throws a syntax error If there are Not enough. -- This is useful For checking the number of arguments available To your aciton. local IRLUA_PLUGIN_CheckNumArgs = function(tbArgs,nArgs) local nCount=table.getn(tbArgs) if nCount < nArgs then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error(nArgs.." Arguments expected, "..nCount.." Arguments passed.\r\n\r\nEventContext: "..sEventContext,3) else error(nArgs.." Arguments expected, "..nCount.." Arguments passed.",3) end end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a string. -- If Not it throws a syntax error. local IRLUA_PLUGIN_CheckString = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "string" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a string, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a string, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a string or a number. -- If Not it throws a syntax error. local IRLUA_PLUGIN_CheckNumString = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "string" and sType ~= "number" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a string or a number, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a string or a number, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a number. -- If Not, it tries To convert it To a number. this is to save use of "tonumber" and "String.ToNumber" while retriveing your functions arguments. -- If it can't convert it To a number it throws a syntax error. local IRLUA_PLUGIN_CheckNumber = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "number" then if tonumber(tbArgs[nArg]) then return tonumber(tbArgs[nArg]); else if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a number, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a number, you passed a "..type(tbArgs[nArg])..".",3) end end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a boolean,. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckBoolean = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "boolean" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a boolean, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a boolean, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a function. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckFunction = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "function" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a function, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a function, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a function or nil. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckFunctionNil = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "function" and sType ~= "nil" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a function or be nil, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a function or be nil, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a thread. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckThread = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "thread" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a thread, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a thread, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a table. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckTable = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "table" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a table, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a table, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- Checks the value at a given argument table position To see If it is a userdata. -- If not it throws a syntax error and exits the function. local IRLUA_PLUGIN_CheckUserData = function(tbArgs,nArg) local sType=type(tbArgs[nArg]) if sType ~= "userdata" then if _ShowErrorEventContext then local sEventContext=Debug.GetEventContext() error("bad argument #" .. nArg .. ", must be a userdata, you passed a "..type(tbArgs[nArg])..".\r\n\r\nEventContext: "..sEventContext,3) else error("bad argument #" .. nArg .. ", must be a userdata, you passed a "..type(tbArgs[nArg])..".",3) end else return tbArgs[nArg] end end --######################################################################################################### -- END IRLUA PLUGIN HELPER FUNCTIONS --######################################################################################################### GlobalPaths = {}; GLOBAL_PATHS_DATA_FOLDER = "AutoPlay"; function GlobalPaths.Initialize() local sDataFolder = GLOBAL_PATHS_DATA_FOLDER; if Table.Count(_CommandLineArgs) == 0 then _ExeFolder = _SourceFolder; local sDataPath = _SourceFolder.."\\"..sDataFolder; _Audio = sDataPath.."\\Audio"; _Buttons = sDataPath.."\\Buttons"; _DLLs = sDataPath.."\\DLLs"; _Docs = sDataPath.."\\Docs"; _Flash = sDataPath.."\\Flash"; _Fonts = sDataPath.."\\Fonts"; _Icons = sDataPath.."\\Icons"; _Images = sDataPath.."\\Images"; _Plugins = sDataPath.."\\Plugins"; _Scripts = sDataPath.."\\Scripts"; _TempAPFolder = sDataPath.."\\Temp"; _Videos = sDataPath.."\\Videos"; sDataPath = "_"..sDataFolder..[[ = ]].."\"".._SourceFolder.."\\"..sDataFolder.."\""; sDataPath = String.Replace(sDataPath, "\\", "\\\\", false); loadstring(sDataPath)(); elseif Table.Count(_CommandLineArgs) > 0 then sSourcePath = _CommandLineArgs[Table.Count(_CommandLineArgs)]; nSourcePathFound = String.Find(sSourcePath, "SFXSOURCE:", 1, false); if nSourcePathFound ~= -1 then sTempPath = String.Replace(sSourcePath, "SFXSOURCE:", "", false); for x = 1, 2 do nFolderLength = String.Length(sTempPath); nErasePoint = String.ReverseFind(sTempPath, "\\", false); sTempExeFolder = String.Left(sTempPath, nFolderLength - (nFolderLength - nErasePoint) - 1); end _ExeFolder = sTempExeFolder; local sDataPath = sDataFolder; _Audio = sDataPath.."\\Audio"; _Buttons = sDataPath.."\\Buttons"; _DLLs = sDataPath.."\\DLLs"; _Docs = sDataPath.."\\Docs"; _Flash = sDataPath.."\\Flash"; _Fonts = sDataPath.."\\Fonts"; _Icons = sDataPath.."\\Icons"; _Images = sDataPath.."\\Images"; _Plugins = sDataPath.."\\Plugins"; _Scripts = sDataPath.."\\Scripts"; _Videos = sDataPath.."\\Videos"; sDataPath = "_"..sDataFolder..[[ = ]].."\""..sDataFolder.."\""; sDataPath = String.Replace(sDataPath, "\\", "\\\\", false); loadstring(sDataPath)(); elseif nSourcePathFound == -1 then _ExeFolder = _SourceFolder; local sDataPath = _SourceFolder.."\\"..sDataFolder; _Audio = sDataPath.."\\Audio"; _Buttons = sDataPath.."\\Buttons"; _DLLs = sDataPath.."\\DLLs"; _Docs = sDataPath.."\\Docs"; _Flash = sDataPath.."\\Flash"; _Fonts = sDataPath.."\\Fonts"; _Icons = sDataPath.."\\Icons"; _Images = sDataPath.."\\Images"; _Plugins = sDataPath.."\\Plugins"; _Scripts = sDataPath.."\\Scripts"; _Videos = sDataPath.."\\Videos"; sDataPath = "_"..sDataFolder..[[ = ]].."\"".._SourceFolder.."\\"..sDataFolder.."\""; sDataPath = String.Replace(sDataPath, "\\", "\\\\", false); loadstring(sDataPath)(); end end function GlobalPaths.GetPaths() local tPaths = {}; tPaths[1] = "_ExeFolder"; tPaths[2] = "_SourceFolder"; tPaths[3] = GLOBAL_PATHS_DATA_FOLDER; tPaths[4] = "_Audio"; tPaths[5] = "_Buttons"; tPaths[6] = "_DLLs"; tPaths[7] = "_Docs"; tPaths[8] = "_Flash"; tPaths[9] = "_Fonts"; tPaths[10] = "_Icons"; tPaths[11] = "_Images"; tPaths[12] = "_Plugins"; tPaths[13] = "_Scripts"; tPaths[14] = "_Videos"; return tPaths end end function GlobalPaths.SetDataFolder(...) IRLUA_PLUGIN_CheckNumArgs(arg, 1); local sNewFolder = IRLUA_PLUGIN_CheckString(arg,1); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< if String.Replace(sNewFolder, " ", "", false) ~= "" then GLOBAL_PATHS_DATA_FOLDER = sNewFolder; GlobalPaths.Initialize(); end end function GlobalPaths.RegisterPaths(...)--, tExcludeFromSimpleMode) IRLUA_PLUGIN_CheckNumArgs(arg, 1); local bSimpleMode = IRLUA_PLUGIN_CheckBoolean(arg,1); --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< local tAllPaths = Folder.Find(_ExeFolder, "*", true, nil); --local tExclusions = {}; if tAllPaths then local sDataFolder = GLOBAL_PATHS_DATA_FOLDER; if bSimpleMode == true then --if tExcludeFromSimpleMode then --for nExIndex, sExFolder in tExcludeFromSimpleMode do --for nIndex, sPath in tAllPaths do -- if String.Find(sPath, _ExeFolder.."\\"..sExFolder, 1, false) ~= -1 then -- tAllPaths[nIndex] = "EXCLUDE"; -- tExclusions[Table.Count(tExclusions) + 1] = sPath; -- Dialog.Message("Excluded and Added to ExTable", sPath); -- end --end -- end --end for nIndex, sPath in tAllPaths do --if sPath ~= "EXCLUDE" then local sEndOfPath = String.Replace(sPath, _ExeFolder, "", true); if String.Left(sEndOfPath, String.Length(sDataFolder)) ~= sDataFolder then local sEndOfPath = String.Replace(sPath, _ExeFolder, "", true); local nLastFolderStart = String.ReverseFind(sEndOfPath, "\\", false); local sLastFolder = String.Right(sEndOfPath, String.Length(sEndOfPath) - nLastFolderStart); local sNewPathVariable = "_"..sLastFolder; sNewPathVariable = String.Replace(sNewPathVariable, " ", "", false); local sPath = String.Replace(sPath, "\\", "\\\\", false); local sLoadString = sNewPathVariable.." = \""..sPath.."\""; loadstring(sLoadString)(); end --end end --if Table.Count(tExclusions) ~= 0 then --for nIndex, sPath in tExclusions do -- if String.Left(sEndOfPath, String.Length(_AutoPlay)) ~= _AutoPlay then -- local sEndOfPath = String.Replace(sPath, _ExeFolder.."\\"..sExFolder, "", true); -- Dialog.Message("", sEndOfPath); -- local sNewPathVariable = String.Replace(sEndOfPath, "\\", "_", false); -- local sPath = String.Replace(sPath, "\\", "\\\\", false); -- local sLoadString = sNewPathVariable.." = \""..sPath.."\""; -- loadstring(sLoadString)(); -- end --end --end else for nIndex, sPath in tAllPaths do local sEndOfPath = String.Replace(sPath, _ExeFolder, "", true); if String.Left(sEndOfPath, String.Length(sDataFolder)) ~= sDataFolder then local sNewPathVariable = String.Replace(sEndOfPath, "\\", "_", false); sNewPathVariable = String.Replace(sNewPathVariable, " ", "", false); local sPath = String.Replace(sPath, "\\", "\\\\", false); local sLoadString = sNewPathVariable.." = \""..sPath.."\""; loadstring(sLoadString)(); end end end end -->>>>>>>> end GlobalPaths.Initialize();