ghoulsblade/lua.js — pull request #1 by ghoulsblade (2012-03-31 00:57:23+00:00)
Title: basic string.match implementation

not fully identical, but passes a few tests of simple cases:

local path = "/Library/Application Support" CheckTrue("match01",string.match(path,"/Library/Application Support"))
CheckTrue("match02",string.match("12ABab99",'^[0123456789abcdefABCDEF]+$'))
local a,b = string.match("myfile.txt","(.+)%.(.-)$") CheckArr("match03",{a,b},{"myfile","txt"})
CheckArr("match04",{string.match("mymusic.mp3","%.[mo][pg][3g]$")},{".mp3"})

function CheckArr (title,arr1,arr2)
for k,v in pairs(arr2) do
print((arr1[k] == v) and "OK" or "ERROR",title,"#"..tostring(k),arr1[k],v)
end
end
function CheckBool (title,testme,shouldbe)
testme = not (not testme)
shouldbe = not (not shouldbe)
print( (testme == shouldbe) and "OK" or "ERROR" , title, testme, shouldbe)
end
function CheckTrue (title,testme) CheckBool(title,testme,true) end

(all 4 tests passed successfully with the suggested implementation)