--######################################################################################################### -- 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 --######################################################################################################### Class = {}; CLASS_PAGE_CLASS_TABLES = {}; CLASS_DIALOG_CLASS_TABLES = {}; CLASS_OBJECT_CLASS_TABLES = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_BUTTON] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_LABEL] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_PARAGRAPH] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_IMAGE] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_FLASH] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_VIDEO] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_WEB] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_INPUT] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_HOTSPOT] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_LISTBOX] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_COMBOBOX] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_PROGRESS] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_TREE] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_RADIOBUTTON] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_RICHTEXT] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_CHECKBOX] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_SLIDESHOW] = {}; CLASS_OBJECT_CLASS_TABLES[OBJECT_GRID] = {}; --==================================== -- BEGIN || HIDDEN FUNCTIONS --==================================== function Class.IsBlank(sInputString) local bRet = -1; --incase of error if sInputString then if String.Replace(sInputString, " ", "", false) == "" then bRet = true; else bRet = false; end end return bRet end function Class.IsDialog() local bRet = false; if Application.GetCurrentDialog() ~= "" then bRet = true; end end --==================================== -- END || HIDDEN FUNCTIONS --==================================== --==================================== -- BEGIN || NORMAL FUNCTIONS --==================================== function Class.DialogDefine(...) IRLUA_PLUGIN_CheckNumArgs(arg,2) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local tDialogProperties = IRLUA_PLUGIN_CheckTable(arg,2) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if not Class.IsBlank(sClass) then local sClass = String.Lower(sClass); CLASS_DIALOG_CLASS_TABLES[sClass] = tDialogProperties; end end function Class.DialogInherit(...) IRLUA_PLUGIN_CheckNumArgs(arg,3) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local sDialogName = IRLUA_PLUGIN_CheckString(arg,2) local bRedraw = IRLUA_PLUGIN_CheckBoolean(arg,3) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> local sRet = ""; if not Class.IsBlank(sClass) then local sClass = String.Lower(sClass); Application.SetDialogProperties(sDialogName, CLASS_DIALOG_CLASS_TABLES[sClass]); sRet = sClass; end if bRedraw == true then DialogEx.Redraw(); end return sRet end function Class.ObjectDefine(...) IRLUA_PLUGIN_CheckNumArgs(arg,3) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local nObjectType = IRLUA_PLUGIN_CheckNumber(arg,2) local tClassProperties = IRLUA_PLUGIN_CheckTable(arg,3) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> local sClass = String.Lower(sClass); if not Class.IsBlank(sClass) then CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass] = tClassProperties; end end function Class.ObjectInherit(...) IRLUA_PLUGIN_CheckNumArgs(arg,4) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local nObjectType = IRLUA_PLUGIN_CheckNumber(arg,2) local sObjectName = IRLUA_PLUGIN_CheckString(arg,3) local bRedraw = IRLUA_PLUGIN_CheckBoolean(arg,4) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> local sRet = ""; if not Class.IsBlank(sClass) then local sClass = String.Lower(sClass); if CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass] then if nObjectType == OBJECT_BUTTON then Button.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_LABEL then Label.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_PARAGRAPH then Paragraph.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_IMAGE then Image.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_FLASH then Flash.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_VIDEO then Video.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_WEB then Web.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_INPUT then Input.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_HOTSPOT then Hotspot.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_LISTBOX then ListBox.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_COMBOBOX then ComboBox.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_PROGRESS then Progress.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_TREE then Tree.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_RADIOBUTTON then RadioButton.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_RICHTEXT then RichText.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_CHECKBOX then CheckBox.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_SLIDESHOW then SlideShow.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); elseif nObjectType == OBJECT_GRID then Grid.SetProperties(sObjectName, CLASS_OBJECT_CLASS_TABLES[nObjectType][sClass]); end sRet = sClass; if bRedraw == true then if Class.IsDialog() == true then DialogEx.Redraw(); elseif Class.IsDialog() == false then Page.Redraw(); end end end end end function Class.PageDefine(...) IRLUA_PLUGIN_CheckNumArgs(arg,2) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local tPageProperties = IRLUA_PLUGIN_CheckTable(arg,2) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if not Class.IsBlank(sClass) then local sClass = String.Lower(sClass); CLASS_PAGE_CLASS_TABLES[sClass] = tPageProperties; end end function Class.PageInherit(...) IRLUA_PLUGIN_CheckNumArgs(arg,3) local sClass = IRLUA_PLUGIN_CheckString(arg,1) local sPageName = IRLUA_PLUGIN_CheckString(arg,2) local bRedraw = IRLUA_PLUGIN_CheckBoolean(arg,3) -->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> local sRet = ""; if not Class.IsBlank(sClass) then local sClass = String.Lower(sClass); Application.SetPageProperties(sPage, sPageName, CLASS_PAGE_CLASS_TABLES[sClass]); sRet = sClass; end if bRedraw == true then Page.Redraw(); end return sRet end --=========================== -- END || NORMAL FUNCTIONS --===========================