Skip to content

Commit

Permalink
Added 'DataFromCommand' function
Browse files Browse the repository at this point in the history
It's a shortcut for obtaining data from the output of a command.
  • Loading branch information
vercas committed Apr 6, 2017
1 parent d912725 commit c55cc71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vmake-2.0.1-19.rockspec → vmake-2.1.0-20.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "vmake"
version = "2.0.1-19"
version = "2.1.0-20"

source = {
url = "git://github.com/vercas/vMake",
tag = "v2.0.1",
tag = "v2.1.0",
}

description = {
Expand Down
29 changes: 24 additions & 5 deletions vmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ local luaVersion = _____________t[1] or _____________t[1/0] or _____________t[__
-- Taken from http://lua-users.org/lists/lua-l/2016-05/msg00297.html

local vmake, vmake__call, getEnvironment, withEnvironment = {
Version = "1.7.0",
VersionNumber = 1007000,
Version = "2.1.0",
VersionNumber = 2001000,

Debug = false,
Silent = false,
Expand Down Expand Up @@ -6263,9 +6263,7 @@ local function generateManagedComponent(compType)
Opts_Includes_Nasm = DAT "Opts_Includes_Nasm_Base",

Opts_Libraries = function()
return Libraries:Select(function(val)
return "-l" .. val
end)
return Libraries:Select(L "|val| '-l' .. val")
end,

Libraries = List { }, -- Default to none.
Expand Down Expand Up @@ -6534,3 +6532,24 @@ end

ManagedProject = generateManagedComponent(Project)
ManagedComponent = generateManagedComponent(Component)

function DataFromCommand(cmd, fnc)
assertType("string", cmd, "cmd", 2)

fnc = fnc or List

return function()
local fp = _G.io.popen(cmd)
local output, a, b, c = fp:read("*a")

if output then
a, b, c = fp:close()
end

if not output or c == 1 then
_G.error("Could not get data from command `" .. cmd .. "`: " .. a .. "; " .. b .. "; " .. c)
end

return fnc(output)
end
end

0 comments on commit c55cc71

Please sign in to comment.