local data ={}
DualStack ={}function DualStack:new(o)o = o or{}self.__index =selfsetmetatable(o,self)data[o]={}return o
endfunction DualStack:push(v)table.insert(data[self],v)endfunction DualStack:pop()local v = data[self][#data[self]]table.remove(data[self],#data[self])return v
endfunction DualStack:top()local v = data[self][#data[self]]return v
endfunction DualStack:isempty()return#data[self]==0endlocal stack = DualStack:new()for i =1,10dostack:push(i)endprint(stack:top())whilenot stack:isempty()doprint(stack:pop())end
lua URL解码
local function unescape(s)s string.gsub(s,""," ")s string.gsub(s,"%%(%x%x)",function(h)return string.char(tonumber(h,16))end)return s
endlocal cgi {}
local function decode(s)for name,value in string.gmatch(s,&q…
lua split实现(lua程序设计10.6练习10.1题)
local function split(s,sp)local t {}local last 1local irepeati string.find(s,sp,last,true)if i thenif i ~ last thent[#t1] string.sub(s,last,i-1)endlast i1elseif last < #s thent[#t1] s…