Some of the most commonly used tool functions of the LUA customization

Source: Internet
Author: User

SK = SK or {}local Xmtool = {}--[[@brief Defined some commonly used functions @by xiaoming]]local countcode = [[ Local i = 0 return function () i = i + 1 return I end]]---custom counter xmtool.x Mcounter = Assert (LoadString (countcode))-----------------------------------get a singleton function for a class [email protected] Clss To obtain the Singleton class [email protected] singleton the Singleton [email protected] that needs to be acquired CLSS Singleton---------------------------------function Xmtool.getsingleton (Clss,singleton,...) Return singleton or clss:new (...) End-----------------------------------------Wraps the callback function so that the class method defines the object of the function that [email protected] obj will call [email     Protected] Method function to invoke---------------------------------------functions Xmtool.handlercall (obj, method)        return function (...)    Return method (obj, ...) EndEnd---------------------------------------------string split [email protected] input string [email protected ] delimiter the character used for the split [email protected] #table/If the delimiterIs null, it returns false-------------------------------------------function xmtool.splitstr (input, delimiter) input = ToString ( Input) delimiter = ToString (delimiter) if (delimiter== ") then return False End local Pos,arr = 0, {}--for E Ach divider found for st,sp in function () return string.find (Input, delimiter, POS, true) end do Table.insert (AR R, String.sub (input, POS, st-1)) pos = sp + 1 End Table.insert (arr, string.sub (input, POS)) return Arren d-------------------------------------string split [email protected] input string [email protected] Delimiter The character used for the split [email protected] #string-----------------------------------function xmtool.getsplitstr (input, delimiter) Local arr = Xmtool.splitstr (input,delimiter) Local str = "" if (Type (arr) ~= "table") then return TOSTR ing (input) else for i=1, #arr do str = str. Arr[i] End end return strend-------------------------------printing information-----------------------------function xmtool.sklOG (...) Print (String.Format (...)) End------------------------------Print log--------------------------------function xmtool.printfuncmsg (Msginfo, Tablefunc) Printinfo (msginfo., file:%s,line:%s ", Tablefunc.source,tablefunc.currentline) End-------------------------------Print the appropriate stack information--msg the custom information we added-----------------------------function Xmtool.printtracemsg (msg) xmtool.sklog ("----------------------------------------") Xmtool.sklog ("msg:"). ToString (msg): "\ n") Xmtool.sklog (Debug.traceback ()) Xmtool.sklog ("----------------------------------------") return msgend-----  -----------------------------------critical function error detection [email protected] func #function function to be detected [email protected] msg custom information [email protected] level error levels--------------------------------------function Xmtool.catcherror (func,msg, Level) local state, message = Xpcall (Func,function () return xmtool.printtracemsg (msg) end) return state or error (Me Ssage,level) End-----------------------------------Convert a number to a percent string [email&Nbsp;protected] Number of digits to convert [email protected] retain number of decimal digits to retain---------------------------------function Xmtool.getpercentstring (number,retain) Local ret = ToString (retain) return String.Format ("%.": Ret.. " F ".." Percent ", number*100) end

Some of the most commonly used tool functions of the LUA customization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.