Sha256: 8dc8aa754e2d05102580cd519964329bab94a5a6ff0d605995bdf972a5abef71

Contents?: true

Size: 981 Bytes

Versions: 17

Compression:

Stored size: 981 Bytes

Contents

--[[--
num_args takes in 5.1 byte code and extracts the number of arguments
from its function header.
--]]--

function int(t)
	return t:byte(1)+t:byte(2)*0x100+t:byte(3)*0x10000+t:byte(4)*0x1000000
end

function num_args(func)
	local dump = string.dump(func)
	local offset, cursor = int(dump:sub(13)), offset + 26
	--Get the params and var flag (whether there's a ... in the param)
	return dump:sub(cursor):byte(), dump:sub(cursor+1):byte()
end

-- Usage:
num_args(function(a,b,c,d, ...) end) -- return 4, 7

-- Python styled string format operator
local gm = debug.getmetatable("")

gm.__mod=function(self, other)
    if type(other) ~= "table" then other = {other} end
    for i,v in ipairs(other) do other[i] = tostring(v) end
    return self:format(unpack(other))
end

print([===[
    blah blah %s, (%d %d)
]===]%{"blah", num_args(int)})

--[=[--
table.maxn is deprecated, use # instead.
--]=]--
print(table.maxn{1,2,[4]=4,[8]=8) -- outputs 8 instead of 2

print(5 --[[ blah ]])

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
agile-proxy-0.1.24 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.23 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.22 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.21 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.20 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.19 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.18 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.13 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.12 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.11 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.10 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.9 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.8 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.7 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.6 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.5 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua
agile-proxy-0.1.4 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/lua.lua