diff --git a/Bladerunner b/Bladerunner index 6f5de2b..7c2521f 100644 --- a/Bladerunner +++ b/Bladerunner @@ -42,6 +42,7 @@ end --cross compile function target.build() + sh.go("generate") go("gox") end @@ -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 diff --git a/luasrc/lua-generated.go b/luasrc/lua-generated.go index 850380f..03f5dbc 100644 --- a/luasrc/lua-generated.go +++ b/luasrc/lua-generated.go @@ -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 = { @@ -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 diff --git a/luasrc/sh.lua b/luasrc/sh.lua index 528ffb0..1821558 100644 --- a/luasrc/sh.lua +++ b/luasrc/sh.lua @@ -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 = { diff --git a/string.go b/string.go index e32e23c..0f8b0dd 100644 --- a/string.go +++ b/string.go @@ -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 { @@ -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 +}