-- $LastChangedDate: 2011-03-17 19:59:52 -0400 (Thu, 17 Mar 2011) $
-- Macros written in Lua to expand C++ code for bindings between C++/Lua.
-- Avoid lua_/LUA_ which is reserved by Lua.

bindTable = {

class = "Keyboard",
typesig = nil,
luaCanInstantiate = false,

headers =
[[
#include "base/module.hh"
using namespace base;
#include "input/module.hh"
using namespace input;
]],

moreComments = "sim.Keyboard abstracts input::KeyboardDevice.\n",

func_DequeueKey = {
    comments = "table|nil Keyboard:DequeueKey()\n * Returns table { press=bool, key=int, lkey=int, shift=bool, ctrl=bool, alt=bool, modifier=bool }. \n * lkey means key converted to lower-case.",
    code = [[
        input::KeyboardEvent keyboardEvent;
        if ( GET_KEYBOARD_DEVICE().Dequeue( keyboardEvent ) )
        {
            lua_newtable( L );
            SET_MEMBER_AS_BOOL( L, "press", keyboardEvent.mPress );
            SET_MEMBER_AS_INT(  L, "key",   keyboardEvent.mKey );
            SET_MEMBER_AS_INT(  L, "lkey",  tolower(keyboardEvent.mKey) );
            SET_MEMBER_AS_BOOL( L, "shift", keyboardEvent.mShift );
            SET_MEMBER_AS_BOOL( L, "ctrl",  keyboardEvent.mCtrl );
            SET_MEMBER_AS_BOOL( L, "alt",   keyboardEvent.mAlt );
            SET_MEMBER_AS_BOOL( L, "modifier", keyboardEvent.IfModifier() );  // true if any modifier (Shift/Ctrl/Alt)
        }
        else
        {
            lua_pushnil( L );  // no event
        }
        return 1;  // stack items to return
    ]]
},

}
