Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes it easier to test SUFs with wesnoth.get_units{} in the lua console.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,28 @@ static int impl_unit_equality(lua_State* L) | |
return 1; | ||
} | ||
|
||
/** | ||
* Turns a lua proxy unit to string. (__tostring metamethod) | ||
*/ | ||
static int impl_unit_tostring(lua_State* L) | ||
{ | ||
const unit& u = luaW_checkunit(L, 1); | ||
std::ostringstream str; | ||
|
||
str << "unit: <"; | ||
if(!u.id().empty()) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jostephd
Author
Member
|
||
str << u.id() << " "; | ||
} else { | ||
str << u.type_id() << " "; | ||
} | ||
// This will say 0,0 (or -999,-999?) for units on the recall list | ||
str << "at (" << u.get_location() << ")"; | ||
str << '>'; | ||
|
||
lua_push(L, str.str()); | ||
return 1; | ||
} | ||
|
||
/** | ||
* Gets some data on a unit (__index metamethod). | ||
* - Arg 1: full userdata containing the unit id. | ||
|
@@ -620,6 +642,8 @@ namespace lua_units { | |
lua_setfield(L, -2, "__gc"); | ||
lua_pushcfunction(L, impl_unit_equality); | ||
lua_setfield(L, -2, "__eq"); | ||
lua_pushcfunction(L, impl_unit_tostring); | ||
lua_setfield(L, -2, "__tostring"); | ||
lua_pushcfunction(L, impl_unit_get); | ||
lua_setfield(L, -2, "__index"); | ||
lua_pushcfunction(L, impl_unit_set); | ||
|
Is unit id allowed to be empty?