-- purpose of this file: Generate libmnoofltk

local libBuilder_cl=require("mnoofltk/libBuilder/libBuilder_cl.lua")
local type_cl=require("mnoofltk/libBuilder/libBuilderType_cl.lua")
local fun_cl=require("mnoofltk/libBuilder/libBuilderFun_cl.lua")

local builder=libBuilder_cl:new{cfile="temp/mnoofltk.cxx", luafile="mnoo_current/mnoofltk.lua", libmain="mnoofltk_api_init", sharedObject="libmnoofltk"}
-- shared object

builder:set_header{file="<FL/Fl.H>", language="C++"}
builder:set_header{file="<FL/Fl_Widget.H>", language="C++"}
builder:set_header{file="<FL/Fl_Button.H>", language="C++"}
builder:set_header{file="<FL/Fl_Check_Button.H>", language="C++"}
builder:set_header{file="<FL/Fl_Group.H>", language="C++"}
builder:set_header{file="<FL/Fl_Tabs.H>", language="C++"}
builder:set_header{file="<FL/Fl_Choice.H>", language="C++"}
builder:set_header{file="<FL/Fl_Input.H>", language="C++"}
builder:set_header{file="<FL/Fl_Scroll.H>", language="C++"}
builder:set_header{file="<FL/Enumerations.H>", language="C++"}
builder:set_header{file="<FL/fl_draw.H>", language="C++"}
builder:set_header{file="<FL/Fl_Double_Window.H>", language="C++"}
builder:set_header{file='<FL/fl_ask.H>', language="C++"}
builder:set_header{file='<FL/fl_message.H>', language="C++"}
--builder:set_header{file="<FL/Fl_Pack.H>", language="C++"}
builder:set_header{file='<FL/Fl_Menu_Button.H>', language="C++"}
builder:set_header{file='"mnoofltk/widgets/callbackArg.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/button.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/checkbutton.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/menubutton.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/canvas.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/choice.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/input.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/group.cxx"', language="C++"}
builder:set_header{file='"mnoofltk/widgets/window.cxx"', language="C++"}

-- fields for functions:
-- n: function name in lua (to be generated)
-- c: function name in C (to be called)
-- r: return type of C function
-- args: {"name=type"}, type of int, double, string, or any lua object type defined with registerType

-- ########################################################################################
-- # Fltk
-- ########################################################################################
local fltk_type=type_cl:new{ctype="//invalid//", luatype="fltk"}
builder:registerType{type=fltk_type}
fltk_type:registerFunction{fun=fun_cl:new{n="wait", c="Fl::wait", args={"time=double"}, r="double"}}
fltk_type:registerFunction{fun=fun_cl:new{n="run", c="Fl::run", args={}, r="int"}}
fltk_type:registerFunction{fun=fun_cl:new{n="begin_line", c="fl_begin_line", args={}}}
fltk_type:registerFunction{fun=fun_cl:new{n="end_line", c="fl_end_line", args={}}}
fltk_type:registerFunction{fun=fun_cl:new{n="vertex", c="fl_vertex", args={"x=int", "y=int"}}}
fltk_type:registerFunction{fun=fun_cl:new{n="set_color", c="fl_color", args={"color=int"}}}
fltk_type:registerFunction{fun=fun_cl:new{n="rgb_color", c="fl_rgb_color", args={"red=int", "green=int", "blue=int"}, r="int"}}
fltk_type:registerFunction{fun=fun_cl:new{n="rect", c="fl_rectf", args={"x=int", "y=int", "w=int", "h=int"}}}
fltk_type:registerFunction{fun=fun_cl:new{n="scheme", c="Fl::scheme", args={"name=string"}}}
fltk_type:registerFunction{fun=fun_cl:new{n="message", c="fl_message", args={"text=string"}}}
fltk_type:registerFunction{fun=fun_cl:new{n="ask", c="fl_ask", args={"text=string"}, r="int"}}

-- ########################################################################################
-- # Fltk widget
-- ########################################################################################
local widget_type=type_cl:new{ctype="Fl_Widget*", luatype="widget"}
builder:registerType{type=widget_type}
widget_type:registerFunction{fun=fun_cl:new{c="->x", n="getx", args={}, r="int"}}
widget_type:registerFunction{fun=fun_cl:new{c="->y", n="gety", args={}, r="int"}}
widget_type:registerFunction{fun=fun_cl:new{c="->w", n="getw", args={}, r="int"}}
widget_type:registerFunction{fun=fun_cl:new{c="->h", n="geth", args={}, r="int"}}
widget_type:registerFunction{fun=fun_cl:new{c="->color", n="set_color", args={"color=int"}}}
widget_type:registerFunction{fun=fun_cl:new{c="->copy_label", n="label", args={"label=string"}}}
widget_type:registerFunction{fun=fun_cl:new{c="->redraw", n="redraw", args={}}}
   
-- ########################################################################################
-- # Fltk button
-- ########################################################################################
local button_type=type_cl:new{ctype="mnoo_Fl_Button*", luatype="button", parent=widget_type}
button_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=button_type}

-- ########################################################################################
-- # Fltk menu button
-- ########################################################################################
local menubutton_type=type_cl:new{ctype="mnoo_Fl_Menu_Button*", luatype="menubutton", parent=widget_type}
menubutton_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
menubutton_type:registerFunction{fun=fun_cl:new{c="->add", n="add", args={"label=string", "callback=luafun", "data=luaany"}}}
builder:registerType{type=menubutton_type}

-- ########################################################################################
-- # Fltk checkbutton
-- ########################################################################################
local checkbutton_type=type_cl:new{ctype="mnoo_Fl_Check_Button*", luatype="checkbutton", parent=widget_type}
checkbutton_type:registerFunction{fun=fun_cl:new{c="->value", n="set_value", args={"value=int"}}}
checkbutton_type:registerFunction{fun=fun_cl:new{c="->value", n="get_value", args={}, r="int"}}
checkbutton_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=checkbutton_type}

-- ########################################################################################
-- # Fltk input
-- ########################################################################################
local input_type=type_cl:new{ctype="mnoo_Fl_Input*", luatype="input", parent=widget_type}
input_type:registerFunction{fun=fun_cl:new{c="->value", n="set_value", args={"value=string"}}}
input_type:registerFunction{fun=fun_cl:new{c="->value", n="get_value", args={}, r="string"}}
input_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=input_type}

-- ########################################################################################
-- # Fltk choice
-- ########################################################################################
local choice_type=type_cl:new{ctype="mnoo_Fl_Choice*", luatype="choice", parent=widget_type}
choice_type:registerFunction{fun=fun_cl:new{c="->get_index", n="get_index", args={}, r="int"}}
choice_type:registerFunction{fun=fun_cl:new{c="->set_index", n="set_index", args={"index=int"}}}
choice_type:registerFunction{fun=fun_cl:new{c="->get_text", n="get_text", args={}, r="string"}}
--choice_type:registerFunction{fun=fun_cl:new{c="->value", n="_set_value", args={"value=int"}}}
choice_type:registerFunction{fun=fun_cl:new{c="->add", n="add", args={"text=string"}, r="int"}}
choice_type:registerFunction{fun=fun_cl:new{c="->clear", n="clear", args={}}}
choice_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=choice_type}

-- ########################################################################################
-- # Fltk group
-- ########################################################################################
local group_type=type_cl:new{ctype="Fl_Group*", luatype="group", parent=widget_type}
builder:registerType{type=group_type}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_button", n="button", args={"~lua", "callback=luafun", "data=luaany", "x=int", "y=int", "w=int", "h=int", "label=string"}, r="button"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_checkbutton", n="checkbutton", args={"~lua", "callback=luafun", "data=luaany", "x=int", "y=int", "w=int", "h=int", "label=string"}, r="checkbutton"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_tabs", n="tabs", args={"x=int", "y=int", "w=int", "h=int"}, r="tabs"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_canvas", n="canvas", args={"~lua", "redraw_fun=luafun", "redraw_data=luaany", "event_fun=luafun", "event_data=luaany", "x=int", "y=int", "w=int", "h=int"}, r="canvas"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_choice", n="choice", args={"~lua", "x=int", "y=int", "w=int", "h=int", "callback=luafun", "data=luaany", "label=string"}, r="choice"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_input", n="input", args={"~lua", "x=int", "y=int", "w=int", "h=int", "callback=luafun", "data=luaany", "label=string"}, r="input"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_scroll", n="scroll", args={"~lua", "x=int", "y=int", "w=int", "h=int"}, r="scroll"}}
group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_menubutton", n="menubutton", args={"~lua", "x=int", "y=int", "w=int", "h=int", "label=string"}, r="menubutton"}}
--group_type:registerFunction{fun=fun_cl:new{c="=>mnoo_group_new_pack", n="pack", args={"x=int", "y=int", "w=int", "h=int"}, r="pack"}}
group_type:registerFunction{fun=fun_cl:new{c="->resize", n="resize", args={"x=int", "y=int", "w=int", "h=int"}}}
group_type:registerFunction{fun=fun_cl:new{c="->remove", n="remove", args={"widget=widget"}}}
group_type:registerFunction{fun=fun_cl:new{c="->clear", n="clear", args={}}}

-- ########################################################################################
-- # Fltk tabs
-- ########################################################################################
local tabs_type=type_cl:new{ctype="Fl_Tabs*", luatype="tabs", parent=group_type}
tabs_type:registerFunction{fun=fun_cl:new{c="=>mnoo_tab_new_page", n="page", args={"label=string"}, r="group"}}
tabs_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=tabs_type}

-- ########################################################################################
-- # Fltk pack
-- ########################################################################################
--local pack_type=type_cl:new{ctype="Fl_Pack*", luatype="pack", parent=group_type}
--builder:registerType{type=pack_type}

-- ########################################################################################
-- # Fltk canvas
-- ########################################################################################
local canvas_type=type_cl:new{ctype="Fl_Group*", luatype="canvas", parent=group_type}
canvas_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=canvas_type}

-- ########################################################################################
-- # Fltk Scroll
-- ########################################################################################
local scroll_type=type_cl:new{ctype="Fl_Scroll*", luatype="scroll", parent=group_type}
scroll_type:registerFunction{fun=fun_cl:new{c="->xposition", n="get_xposition", args={}, r="int"}}
scroll_type:registerFunction{fun=fun_cl:new{c="->yposition", n="get_yposition", args={}, r="int"}}
scroll_type:registerFunction{fun=fun_cl:new{c="->position", n="set_position", args={"x=int", "y=int"}}}
scroll_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}
builder:registerType{type=scroll_type}

-- ########################################################################################
-- # Fltk doubleWindow
-- ########################################################################################
local window_type=type_cl:new{ctype="mnoo_Fl_Window*", luatype="window", parent=group_type}
builder:registerType{type=window_type}
window_type:registerFunction{fun=fun_cl:new{n="new", c="new mnoo_Fl_Window", args={"~lua", "callback=luafun", "data=luaany", "x=int", "y=int", "w=int", "h=int"}, r="window"}}
window_type:registerFunction{fun=fun_cl:new{c="->show", args={}}}
window_type:registerFunction{fun=fun_cl:new{c="->hide", args={}}}
window_type:registerFunction{fun=fun_cl:new{c="->size_range", args={"minw=int", "minh=int", "maxw=int", "maxh=int"}}}
window_type:registerFunction{fun=fun_cl:new{c="->label", n="label", args={"label=string"}, overloaded=true}} -- fixme
window_type:registerFunction{fun=fun_cl:new{c="delete", n="delete", args={}}}

builder:write{}

-- ########################################################################################
-- # Compile
-- ########################################################################################
--assert(os.execute("gcc temp/mnoofltk.cxx -I. -O3 -Wall -o lib/libmnoofltk.so -fPIC `fltk-config --ldstaticflags` -shared -llua -llualib -lstdc++") == 0)
--assert(os.execute("gcc temp/mnoofltk.cxx -I. -O3 -Wall -c -o temp/mnoofltk.o; ar rcs lib/libmnoofltk.a temp/mnoofltk.o; ranlib lib/libmnoofltk.a") == 0)