Skip to content

Commit

Permalink
Added trim on string meta table
Browse files Browse the repository at this point in the history
  • Loading branch information
otm committed Nov 29, 2015
1 parent 30b3793 commit e985cea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Bladerunner
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ end

--cross compile
function target.build()
sh.go("generate")
go("gox")
end

Expand All @@ -53,7 +54,7 @@ function target.goxSetup()
end

function go(cmd, options)
code, gopath = blade._sh("go env GOPATH")
code, gopath = blade.system("go env GOPATH")
gopath = (gopath:gsub("^%s*(.-)%s*$", "%1"))
cmd = gopath .. "/bin/" .. cmd
if options and options.sudo then
Expand Down
5 changes: 2 additions & 3 deletions luasrc/lua-generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ local function command(cmd, ...)
f:close()
s = s .. ' <'..M.tmpfile
end
print("cmd", s)
local exit, output, stderr = blade.system(s)
-- local p = io.popen(s, 'r')
-- local output = p:read('*a')
-- local _, exit, status = p:close()
os.remove(M.tmpfile)
local t = {
Expand Down Expand Up @@ -211,6 +209,7 @@ sudo = sh.sudo
-- export command() function and configurable temporary "input" file
M.command = sh.command
M.subcommand = sh.subcommand
M.tmpfile = '/tmp/shluainput'
-- allow to call sh to run shell commands
Expand Down
4 changes: 1 addition & 3 deletions luasrc/sh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ local function command(cmd, ...)
f:close()
s = s .. ' <'..M.tmpfile
end
print("cmd", s)

local exit, output, stderr = blade.system(s)
-- local p = io.popen(s, 'r')
-- local output = p:read('*a')
-- local _, exit, status = p:close()
os.remove(M.tmpfile)

local t = {
Expand Down
10 changes: 10 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func decorateStringLib(L *lua.LState) {
mt := L.GetMetatable(lua.LString("")).(*lua.LTable)
mt.RawSetString("split", L.NewClosure(split))
mt.RawSetString("c", L.NewClosure(word))
mt.RawSetString("trim", L.NewClosure(trim))
}

func split(L *lua.LState) int {
Expand Down Expand Up @@ -59,3 +60,12 @@ func word(L *lua.LState) int {
L.Push(lua.LString(parts[i-1]))
return 1
}

func trim(L *lua.LState) int {
s := L.CheckString(1)
cutset := L.OptString(2, "\n ")

s = strings.Trim(s, cutset)
L.Push(lua.LString(s))
return 1
}

0 comments on commit e985cea

Please sign in to comment.