From eaaf57114cfb74c29f1b0c4e9786bed6d225225c Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Wed, 15 Jun 2022 23:36:43 -0400 Subject: Initial setup commit This setups up the project for messing around with C++ and Lua bindings. So far this project just prints the defined dng map and lets you move the character around. What this fails to do is actually provide any reason to use Lua at the moment. So I need to figure out some way of enabling logic on the processing side of things. --- src/Api.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/Api.h (limited to 'src/Api.h') diff --git a/src/Api.h b/src/Api.h new file mode 100644 index 0000000..da763c2 --- /dev/null +++ b/src/Api.h @@ -0,0 +1,71 @@ +#ifndef DNG_API_H +#define DNG_API_H + +#include "Level.h" +#include +#include + +extern std::shared_ptr lvl; + +static int +c_update_player_pos(lua_State* L) +{ + // stack ordering + int dy = static_cast(lua_tonumber(L, -1)); + int dx = static_cast(lua_tonumber(L, -2)); + + bool res = false; + + if (lvl->canStep(dx, dy)) { + lvl->player.x += dx; + lvl->player.y += dy; + res = true; + } + + lua_pushboolean(L, res); + + return 1; +} + +static int +c_player_can_move(lua_State* L) +{ + // stack ordering + int dy = static_cast(lua_tonumber(L, -1)); + int dx = static_cast(lua_tonumber(L, -2)); + + bool res = lvl->canStep(dx, dy); + lua_pushboolean(L, res); + + return 1; +} + +static int +c_enemy_can_move(lua_State* L) +{ + return 1; +} + +static int +c_spawn_enemy(lua_State* L) +{ + return 1; +} + +static int +c_destroy_enemy(lua_State* L) +{ + return 1; +} + +static void +init_c_api(lua_State* L) +{ + lua_register(L, "c_update_player_pos", c_update_player_pos); + lua_register(L, "c_player_can_move", c_player_can_move); + lua_register(L, "c_enemy_can_move", c_enemy_can_move); + lua_register(L, "c_spawn_enemy", c_spawn_enemy); + lua_register(L, "c_destroy_enemy", c_destroy_enemy); +} + +#endif // DNG_API_H \ No newline at end of file -- cgit v1.2.3-54-g00ecf