Last active
August 29, 2015 14:19
-
-
Save OmegaExtern/26129e6fc80b333dc46e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Solution for: http://facepunch.com/showthread.php?t=1462506&p=47602760&viewfull=1#post47602760 | |
local getinfo, getlocal, gsub = debug.getinfo, debug.getlocal, string.gsub | |
string.Interp = function(str, tbl) | |
local funcname = getinfo(1.0, "n").name | |
assert(funcname == "Interp", "nope.") | |
for argc = 1.0, getinfo(1.0).nparams, 1.0 do | |
local argname = getlocal(1.0, argc) | |
-- Hard-coded with <3 by OmegaExtern. | |
if argc == 1.0 and argname == "str" then | |
assert(type(str) == "string" and isstring(str), Format("bad argument #%i (%s) to '%s' (string expected, got %s)", argc, argname, funcname, type(str))) | |
elseif argc == 2.0 and argname == "tbl" then | |
assert(type(tbl) == "table" and istable(tbl), Format("bad argument #%i (%s) to '%s' (table expected, got %s)", argc, argname, funcname, type(tbl))) | |
else | |
error("nope.") | |
end | |
end | |
return gsub(str, "{(%w+)}", tbl) | |
end | |
local out = Format("{%s}", string.Interp("m {m} x {x} c {cr} {cg} {cb} r {r} y {y} sa {sa} dt {dt} su {su}", | |
{ | |
m = "gui/center_gradient", | |
x = 181.0, | |
cr = 0.0, | |
cg = 0.0, | |
cb = 0.0, | |
r = 0.0, | |
y = 27.0, | |
sa = 50.0, | |
dt = "default", | |
su = 50.0 | |
} -- Input your (valid) "drawtable" table here. | |
) | |
) | |
print(out) --Outputs:{m gui/center_gradient x 181 c 0 0 0 r 0 y 27 sa 50 dt default su 50} | |
-- On saving, call util.Compress(string): | |
file.Write("picture_1.txt", util.Compress(out)) | |
-- On opening, call util.Decompress(string): | |
util.Decompress(file.Read("picture_1.txt")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment