I been fiddling with lua for a long time and never knew about the integer division operator.

With lua 5.3, there's the // operator for integer division.

So you don't need to always use math.floor to make sure that your parameters are integers.

Just divide by 1 with the integer division operator.

12.1 // 1 returns 12.0

5.9 // 1 returns 5.0

7.1 // 3.5 returns 2.0

so for example the set_element_state_callback() needs an integer return value, and errors out if you have a floating point value.

The layout plugin doesn't make the math module available, so this is a workaround.


Adding math to the the layout plugin is pretty easy though: (plugins/layout/init.lua)

Code
function layout.startplugin()
        local scripts = {}
        local function prepare_layout(file, script)
                local env = {
                        machine = manager.machine,
                        emu = {
                                render_bounds = emu.render_bounds,
                                render_color = emu.render_color,
                                print_verbose = emu.print_verbose,
                                print_error = emu.print_error,
                                print_info = emu.print_info,
                                print_debug = emu.print_debug },
                        math = math,
                        file = file,
                        print = print,
                        pairs = pairs,
                        ipairs = ipairs,
                        string = { format = string.format },
                        table = { insert = table.insert, remove = table.remove } }
                local script, err = load(script, script, "t", env)