Skip to content

Commit

Permalink
lua binding for roads
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Oct 19, 2024
1 parent 4c58fa2 commit 1f5a78a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/bind_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ static int tolua_region_get_adj(lua_State * L)
return 1;
}

static int tolua_region_get_roads(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, NULL);
int d, idx;

lua_createtable(L, MAXDIRECTIONS, 0);
for (d = 0, idx = 0; d != MAXDIRECTIONS; ++d) {
lua_pushinteger(L, rroad(r, d));
lua_rawseti(L, -2, ++idx);
}
return 1;
}

static int tolua_region_get_luxury(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, NULL);
Expand Down Expand Up @@ -815,6 +828,7 @@ void tolua_region_open(lua_State * L)
tolua_function(L, "set_flag", tolua_region_set_flag);
tolua_function(L, "next", tolua_region_get_next);
tolua_variable(L, "adj", tolua_region_get_adj, NULL);
tolua_variable(L, "roads", tolua_region_get_roads, NULL);

tolua_variable(L, "luxury", &tolua_region_get_luxury,
&tolua_region_set_luxury);
Expand Down

0 comments on commit 1f5a78a

Please sign in to comment.