moai/moai-dev — Issue #90: API: have constructors accept a table for initialization?
Author: pygy
Created: 2012-01-12 15:56:40+00:00
State: open

I find this:

local textbox = MOAITextBox.new {
font = font,
textSize = font:getScale (),
rect = { -160, -80, 160, 80 },
alignment = MOAITextBox.CENTER_JUSTIFY,
yFlip = true,
string = "You are dead!"
}
lighter than this:

local textbox = MOAITextBox.new ()
textbox:setFont ( font )
textbox:setTextSize ( font:getScale ())
textbox:setRect ( -160, -80, 160, 80 )
textbox:setAlignment ( MOAITextBox.CENTER_JUSTIFY )
textbox:setYFlip ( true )
textbox:setString ( "You are dead!" )

a similar `object:setParam(tbl)` could share the implementation.

In the same vein, `one, two, three = object:getParams {"one","two","three"}` would also be cool.

In both cases, the implementation may be hairy, though (Recursively call the parent constructors? How do you bind strings to methods in C++ without making a big switch statement?)