11 void LuaFuncs::Push( lua_State
*L
)
14 luaL_register( L
, "map", lMapFuncs
);
16 luaL_register( L
, "player", lPlayerFuncs
);
20 LUA_FUNC( LuaFuncs::Map_Acid
)
22 int largc
= lua_gettop( L
);
24 return luaL_error( L
, "Got %d arguments, needed exactly 2!", largc
);
26 Uint8 X
= (Uint8
)luaL_checknumber( L
, 1 );
27 Uint8 Y
= (Uint8
)luaL_checknumber( L
, 2 );
29 Game::getMap()->Acid( X
, Y
);
34 LUA_FUNC( LuaFuncs::Map_CreateObject
)
36 int largc
= lua_gettop( L
);
38 return luaL_error( L
, "Got %d arguments, needed exactly 3!", largc
);
40 const char *objname
= luaL_checkstring( L
, 1 );
41 Uint8 X
= (Uint8
)luaL_checknumber( L
, 2 );
42 Uint8 Y
= (Uint8
)luaL_checknumber( L
, 3 );
44 Game::getMap()->insertObject( new Object( Game::objectTypes
[objname
] ) , X
, Y
);
49 LUA_FUNC( LuaFuncs::Map_CreateRobot
)
51 int largc
= lua_gettop( L
);
53 return luaL_error( L
, "Got %d arguments, needed exactly 2!", largc
);
55 Uint8 X
= (Uint8
)luaL_checknumber( L
, 1 );
56 Uint8 Y
= (Uint8
)luaL_checknumber( L
, 2 );
58 Game::getMap()->insertRobot( X
, Y
);
64 LUA_FUNC( LuaFuncs::Player_GetPosition
)
66 Player
*p
= Game::getPlayer();
70 lua_pushstring( L
, "x" );
71 lua_pushnumber( L
, p
->getMapX() );
72 lua_settable( L
, -3 );
74 lua_pushstring( L
, "y" );
75 lua_pushnumber( L
, p
->getMapY() );
76 lua_settable( L
, -3 );
81 LUA_FUNC( LuaFuncs::Player_SetImmune
)
83 int largc
= lua_gettop( L
);
85 return luaL_error( L
, "Got %d arguments, needed exactly 1!", largc
);
87 bool newstate
= (bool)luaL_checknumber( L
, 1 );
89 Game::getPlayer()->SetImmune( newstate
);
94 LUA_FUNC( LuaFuncs::Player_Teleport
)
96 int largc
= lua_gettop( L
);
98 return luaL_error( L
, "Got %d arguments, needed exactly 2!", largc
);
100 Uint8 X
= (Uint8
)luaL_checknumber( L
, 1 );
101 Uint8 Y
= (Uint8
)luaL_checknumber( L
, 2 );
103 Game::getPlayer()->Teleport( X
, Y
);
108 LUA_FUNC( LuaFuncs::Player_Pickup
) { return 0; }
110 LUA_FUNC( LuaFuncs::Player_Drop
) { return 0; }
112 const luaL_Reg
LuaFuncs::lMapFuncs
[] = {
114 {"CreateObject", Map_CreateObject
},
115 {"CreateRobot", Map_CreateRobot
},
119 const luaL_Reg
LuaFuncs::lPlayerFuncs
[] = {
120 { "getPosition", Player_GetPosition
},
121 { "setImmune", Player_SetImmune
},
122 { "teleport", Player_Teleport
},
123 { "pickup", Player_Pickup
},
124 { "drop", Player_Drop
},