local data = { -- simple copy/paste then find+replace in selection "\n" -> ",\n" addsoundentry("NULL.VOC", DIGI_NULL, 0, 0, 0, 0, DIST_NORMAL, VF_NORMAL), addsoundentry("SWRDSTR1.VOC", DIGI_SWORDSWOOSH, PRI_HI_PLAYERWEAP, -200, 200, 0, DIST_NORMAL, VF_NORMAL), addsoundentry("THROW.VOC", DIGI_STAR, PRI_HI_PLAYERWEAP, -100, 100, 0, DIST_NORMAL, VF_NORMAL), addsoundentry("STRCLNK.VOC", DIGI_STARCLINK, PRI_PLAYERAMBIENT, 0, 0, 0, DIST_NORMAL, VF_NORMAL), addsoundentry("NULL.VOC", DIGI_NULL_STARWIZ, PRI_LOW_PLAYERWEAP, 0, 0, 0, DIST_NORMAL, VF_LOOP), addsoundentry("UZIFIRE1.VOC", DIGI_UZIFIRE, PRI_HI_PLAYERWEAP, 0, 0, 0, DIST_NORMAL, VF_NORMAL), }
then I write a dummy function to generate the table entries for me, as well as overriding the global table's __index metamethod so that I don't need to manually set DIGI_NULL to "DIGI_NULL" and so forth for every value:
setmetatable(_G, { __index = function(t, k) -- return string for nonexistent values -- saves needing to manually specify each value return k end, }) function addsoundentry(name, id, pri, pitch_lo, pitch_hi, voc_num, voc_dist, voc_flags) return { name = name, id = id, pri = pri, pitch_lo = pitch_lo, pitch_hi = pitch_hi, voc_num = voc_num, voc_dist = voc_dist, voc_flags = voc_flags, } end
Then I just use a simple bit of code to output a table:
local file = io.open("out.lua", "wb") file:write "sounds =\n{\n" for k, soundentry in ipairs(data) do file:write " {\n" for k, v in pairs(soundentry) do if type(v) == "string" then file:write(string.format(" %s = %q,\n", k, v)) else file:write(string.format(" %s = %s,\n", k, v)) end end file:write " },\n\n" end file:write "}" file:close()
Which yields this in out.lua:
sounds = { { voc_flags = "VF_NORMAL", pri = 0, pitch_hi = 0, id = "DIGI_NULL", voc_dist = "DIST_NORMAL", pitch_lo = 0, name = "NULL.VOC", voc_num = 0, }, { voc_flags = "VF_NORMAL", pri = "PRI_HI_PLAYERWEAP", pitch_hi = 200, id = "DIGI_SWORDSWOOSH", voc_dist = "DIST_NORMAL", pitch_lo = -200, name = "SWRDSTR1.VOC", voc_num = 0, }, { voc_flags = "VF_NORMAL", pri = "PRI_HI_PLAYERWEAP", pitch_hi = 100, id = "DIGI_STAR", voc_dist = "DIST_NORMAL", pitch_lo = -100, name = "THROW.VOC", voc_num = 0, }, { voc_flags = "VF_NORMAL", pri = "PRI_PLAYERAMBIENT", pitch_hi = 0, id = "DIGI_STARCLINK", voc_dist = "DIST_NORMAL", pitch_lo = 0, name = "STRCLNK.VOC", voc_num = 0, }, { voc_flags = "VF_LOOP", pri = "PRI_LOW_PLAYERWEAP", pitch_hi = 0, id = "DIGI_NULL_STARWIZ", voc_dist = "DIST_NORMAL", pitch_lo = 0, name = "NULL.VOC", voc_num = 0, }, { voc_flags = "VF_NORMAL", pri = "PRI_HI_PLAYERWEAP", pitch_hi = 0, id = "DIGI_UZIFIRE", voc_dist = "DIST_NORMAL", pitch_lo = 0, name = "UZIFIRE1.VOC", voc_num = 0, }, }
Edit: and with a few small changes you can get it generating the comments, too