-
Notifications
You must be signed in to change notification settings - Fork 5
Lua vs Cpp
doyousketch2 edited this page Sep 13, 2019
·
1 revision
In general there are the following differences between Lua API and C++
API (assuming you did a local fl = require( "fltk4lua" )
at the top
of your Lua source file):
- The prefixes of classes and functions have been removed, so use
-
fl.message()
instead offl_message()
-
fl.run()
instead ofFl::run()
-
fl.Box()
instead ofnew Fl_Box()
-
fl.ALIGN_CENTER
instead ofFL_ALIGN_CENTER
(but see below).
-
- Some
enum
s or preprocessor macros are translated to strings:-
"FL_UP_BOX"
instead ofFL_UP_BOX
.
-
- The remaining
enum
s/macros are available as userdata, so that you can combine them using bitwise operators (in Lua 5.3) or the following alternative operators:-
local a = fl.ALIGN_TOP + fl.ALIGN_LEFT
instead ofFl_Align a = FL_ALIGN_TOP | FL_ALIGN_LEFT;
-
local a = b - fl.ALIGN_LEFT
instead ofFl_Align a = b & (~FL_ALIGN_LEFT);
and -
if a( fl.ALIGN_TOP ) then
instead ofif( a & FL_ALIGN_TOP )
(more specifically it's!(~a & FL_ALIGN_TOP)
, but that only matters when multiple bits are set in the right-hand-side).
-
- C++ method calls are translated to Lua properties whenever
possible, so use
-
b.box = "FL_UP_BOX"
instead ofb->box( FL_UP_BOX );
and -
local bt = b.box
instead ofFl_Boxtype bt = b->box();
.
-
- Integers used as boolean values are translated to real
boolean
s. -
nil
is translated toNULL
ifNULL
is allowed (and vice versa). - Output parameters end up as (multiple) return values.
- The menu interface is a bit different, though, as it is completely
index based, and the
Fl_Menu_Item
s are not exposed as userdata. Instead there are extra methods on the widget that contains the menu items.