0% found this document useful (0 votes)
26 views2 pages

(Fe bypass)hammer.lua

The document defines a Lua module named 'hammer' that includes functionalities for string manipulation, capturing system command output, and parsing command line arguments. It provides methods to split strings, capture command output with optional formatting, and retrieve command line options into a table. The module exports its functions to the global namespace for use in other scripts.

Uploaded by

hatb4095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

(Fe bypass)hammer.lua

The document defines a Lua module named 'hammer' that includes functionalities for string manipulation, capturing system command output, and parsing command line arguments. It provides methods to split strings, capture command output with optional formatting, and retrieve command line options into a table. The module exports its functions to the global namespace for use in other scripts.

Uploaded by

hatb4095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

local hammer = {}

local modules = {
os = {},
string = {},
cmdline = {},
}

local M = modules

-- split string with pattern into a table


function M.string.split(str, pat)
local tinsert = table.insert
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
tinsert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
tinsert(t, cap)
end
return t
end

-- capture the output of system cmd.


function M.os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end

-- parse cmdline to a table


function M.cmdline.get_opt( arg, options )
local tab = {}
for k, v in ipairs(arg) do
if string.sub( v, 1, 2) == "--" then
local x = string.find( v, "=", 1, true )
if x then tab[ string.sub( v, 3, x-1 ) ] = string.sub( v, x+1 )
else tab[ string.sub( v, 3 ) ] = true
end
elseif string.sub( v, 1, 1 ) == "-" then
local y = 2
local l = string.len(v)
local jopt
while ( y <= l ) do
jopt = string.sub( v, y, y )
if string.find( options, jopt, 1, true ) then
if y < l then
tab[ jopt ] = string.sub( v, y+1 )
y = l
else
tab[ jopt ] = arg[ k + 1 ]
end
else
tab[ jopt ] = true
end
y = y + 1
end
end
end
return tab
end

function hammer.exports()
for mod, funcs in pairs(modules) do
local G_mod = _G[mod]
if not G_mod then
G_mod = {}
_G[mod] = G_mod
end

for name, f in pairs(funcs) do


G_mod[name] = f
end
end
end

return hammer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy