#!/home/nop/lua-fltk/flua
-- This is how *all* callbacks show up in lua-land, with w as the widget
function fltk_dispatch(w) if w.callback then w:callback() end end

function f_to_c(f) return (f - 32) * (5/9) end
function c_to_f(c) return c * (9/5) + 32 end

w = Fl_Window:new(254,180,"Temperature converter")

i1 = Fl_Float_Input:new(95,25,85,25)
i1:label("Farenheit:")
i1:value("32.00")
fl_cb(i1)  -- register for callbacks
function i1:callback() 
   local v = f_to_c(self:value())
   local s = format("%.2f", v)
   i2:value(s)
end

i2 = Fl_Float_Input:new(95, 65, 85, 25)
i2:label("Celsius:")
i2:value("0.00")
fl_cb(i2)
function i2:callback() 
   local v = c_to_f(self:value())
   local s = format("%.2f", v)
   i1:value(s)
end

b = Fl_Button:new(85, 110, 90, 30, "&Print")
fl_cb(b)
function b:callback() print("i1 value", i1:value(), "i2 value", i2:value()) end
-- function b:callback() fl_alert("bite me!") end

w:end_layout()
w:show()
