Skip to content

Commit

Permalink
Add wesnoth.map.read_direction
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 4, 2021
1 parent 818cccd commit 43dc85c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -550,6 +550,7 @@ lua_kernel_base::lua_kernel_base()
{ "distance_between", &lua_map_location::intf_distance_between },
{ "get_in_basis_N_NE", &lua_map_location::intf_get_in_basis_N_NE },
{ "get_relative_dir", &lua_map_location::intf_get_relative_dir },
{ "read_direction", &lua_map_location::intf_read_direction },
{ nullptr, nullptr }
};

Expand Down
11 changes: 11 additions & 0 deletions src/scripting/lua_map_location_ops.cpp
Expand Up @@ -28,6 +28,17 @@

namespace lua_map_location {

int intf_read_direction(lua_State* L)
{
map_location::DIRECTION dir = map_location::parse_direction(luaL_checkstring(L, 1));
if(dir == map_location::NDIRECTIONS) {
lua_pushnil(L);
} else {
lua_push(L, map_location::write_direction(dir));
}
return 1;
}

/**
* Expose map_location::get_direction function to lua
* Arg 1: a location
Expand Down
1 change: 1 addition & 0 deletions src/scripting/lua_map_location_ops.hpp
Expand Up @@ -23,6 +23,7 @@ struct lua_State;

namespace lua_map_location {

int intf_read_direction(lua_State* L);
int intf_get_direction(lua_State*);
int intf_vector_sum(lua_State*);
int intf_vector_diff(lua_State*);
Expand Down

0 comments on commit 43dc85c

Please sign in to comment.