summaryrefslogtreecommitdiff
path: root/dalos-luafilter.lua
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-12-23 17:17:07 +0100
committerPixel <pixel@nobis-crew.org>2009-12-23 17:17:07 +0100
commitc36c9d0a335f9dffd1baddced837557b4a669a79 (patch)
treed7cac6e401d1678ee9c5621ad6a8f8954bed928b /dalos-luafilter.lua
parentf045d8db17b4c7c2ecfec2ef24039fdb350bab07 (diff)
A few bugfixes, and adding the template system.
Diffstat (limited to 'dalos-luafilter.lua')
-rw-r--r--dalos-luafilter.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/dalos-luafilter.lua b/dalos-luafilter.lua
index 8181442..0abf40a 100644
--- a/dalos-luafilter.lua
+++ b/dalos-luafilter.lua
@@ -32,11 +32,9 @@ end
if not metatable then metatable = {} end
local oldni, oldi = metatable.__newindex, metatable.__index
metatable.__newindex = function (table, key, value)
--- print("Setting _G[" .. key .. "] = " .. tostring(value))
localenv[key] = value
end
metatable.__index = function (table, key)
--- print("Getting _G[" .. key .. "]")
local l = localenv[key]
if l then return localenv[key] end
return rawget(_G, key)
@@ -87,12 +85,32 @@ end
self:run_in_localenv("input_change", ind)
end,
+ load_template = function (self)
+ local dlg = iup.filedlg {
+ dialogtype = "Open",
+ filter = "*.dtpl",
+ }
+ iup.Popup(dlg)
+ if dlg.status == -1 then return end
+
+ local s, v = pcall(Input, dlg.value)
+ if not s then error("Problem loading file " .. dlg.value) end
+ local f = preload(v)
+ if not f then error("Syntax error loading file " .. dlg.value) end
+ local data, otype, tname = f()
+ if otype ~= "Lua Filter" then error("Wrong template type: " .. otype) end
+
+ self.extra.code = data.template.code
+ end,
+
configure = function (self)
local okay = false
local text = iup.text { multiline = "Yes", font = "Courier", expand = "Yes", value = self.extra.code }
local bok = iup.button { title = "Ok", action = function () okay = true return iup.CLOSE end }
+ local bimport = iup.button { title = "Import", action = function() self:load_template() return iup.CLOSE end }
+ local bexport = iup.button { title = "Export", action = function() self:save_template{ code = self.extra.code } end }
local bcancel = iup.button { title = "Cancel", action = function () okay = false return iup.CLOSE end }
- local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" }
+ local dlg = iup.dialog { iup.vbox { text, iup.hbox { bok, bimport, bexport, iup.fill{}, bcancel, normalizesize = "Horizontal" } }, title = "Code for " .. self.name, size = "600x300" }
local r = dlg:popup()
-- if r ~= iup.NOERROR then return end
local newcode = text.value
@@ -128,6 +146,7 @@ end
obj.load_code = dalosp.luafilter.load_code
obj.run_in_localenv = dalosp.luafilter.run_in_localenv
+ obj.load_template = dalosp.luafilter.load_template
obj:load_code(extra.code)
return obj