diff options
author | Steph Enders <smenders@gmail.com> | 2022-06-15 23:36:43 -0400 |
---|---|---|
committer | Steph Enders <smenders@gmail.com> | 2022-06-15 23:36:43 -0400 |
commit | eaaf57114cfb74c29f1b0c4e9786bed6d225225c (patch) | |
tree | 8f4946942a9f93f2bba8b1c4c39045e8ee02811d /src/Api.h |
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.
Diffstat (limited to 'src/Api.h')
-rw-r--r-- | src/Api.h | 71 |
1 files changed, 71 insertions, 0 deletions
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 <lua.hpp> +#include <memory> + +extern std::shared_ptr<Level> lvl; + +static int +c_update_player_pos(lua_State* L) +{ + // stack ordering + int dy = static_cast<int>(lua_tonumber(L, -1)); + int dx = static_cast<int>(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<int>(lua_tonumber(L, -1)); + int dx = static_cast<int>(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 |