From 3964c8a5816822826647229d4979bb04cf2767c5 Mon Sep 17 00:00:00 2001 From: Warmist Date: Wed, 28 Nov 2012 17:40:37 +0200 Subject: [PATCH] gm-editor, set field to lua return value. --- scripts/gui/gm-editor.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index ce169dedc..b288b8a25 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -169,6 +169,19 @@ function GmEditorUi:onRenderBody( dc) current_item=current_item+1 end +end +function GmEditorUi:set(input) + local trg=self:currentTarget() + + if input== nil then + dialog.showInputPrompt("Set to what?","Lua code to set to (v cur target):",COLOR_WHITE,"",dfhack.curry(self.set,self)) + return + end + local e,what=load("return function(v) return "..input.." end") + if e==nil then + dialog.showMessage("Error!","function failed to compile\n"..what,COLOR_RED) + end + trg.target[trg.keys[trg.selected]]=e()(trg) end function GmEditorUi:onInput(keys) if self.mode==MODE_BROWSE then @@ -190,6 +203,8 @@ end dialog.showMessage("Offset",string.format("Size hex=%x,%x dec=%d,%d",size,off,size,off),COLOR_WHITE) elseif keys.CUSTOM_ALT_F then self:find() + elseif keys.CUSTOM_ALT_S then + self:set() elseif keys.CUSTOM_ALT_E then --self:specialEditor() elseif keys.CUSTOM_ALT_I then --insert