Difference between revisions of "User:Tails"

From Multi Theft Auto: Wiki
(Created page with "==Useful Functions created by Tails== <section name="check" class="both" show="false"> *check <span style="color:gray; font-family:'Georgia',sans-serif; font-size:smaller;...")
 
(Useful Functions created by Tails)
Line 4: Line 4:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
function check(pattern, ...)
 
function check(pattern, ...)
if not pattern or type(pattern) ~= 'string' then check('s', pattern) end
+
if type(pattern) ~= 'string' then check('s', pattern) end
 
local types = {s = "string", n = "number", b = "boolean", f = "function", t = "table", u = "userdata"}
 
local types = {s = "string", n = "number", b = "boolean", f = "function", t = "table", u = "userdata"}
 
for i=1, #pattern do
 
for i=1, #pattern do
 
local c = pattern:sub(i,i)
 
local c = pattern:sub(i,i)
local t = arg.n > 0 and type(arg[i])
+
local t = #arg > 0 and type(arg[i])
 
if not t then error('got pattern but missing args') end
 
if not t then error('got pattern but missing args') end
if t ~= types[c] then error("bad argument #"..i.. " to '"..debug.getinfo(2, "n").name.."' ("..types[c].." expected, got "..tostring(t)..")", 3) end
+
if t ~= types[c] then error(("bad argument #%s to '%s' (%s expected, got %s)"):format(i, debug.getinfo(2, "n").name, types[c], tostring(t)), 3) end
 
end
 
end
 
end
 
end

Revision as of 17:19, 23 July 2018

Useful Functions created by Tails

Click to expand [+]
check
Click to expand [+]
guiGridListGetColumnIDFromTitle