summaryrefslogtreecommitdiff
path: root/library/LuaWrapper.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-18 19:18:49 +0400
committerAlexander Gavrilov2012-05-18 19:18:49 +0400
commit4aa6dbdd005c8930f2ae972e780caa3fde97f854 (patch)
treef29f5027d6a827c25a7123e4f946d82c3976cd46 /library/LuaWrapper.cpp
parente2f39368b17bbc9d6b380faed7ceb52b1bd8eb2d (diff)
downloaddfhack-4aa6dbdd005c8930f2ae972e780caa3fde97f854.tar.gz
dfhack-4aa6dbdd005c8930f2ae972e780caa3fde97f854.tar.bz2
dfhack-4aa6dbdd005c8930f2ae972e780caa3fde97f854.tar.xz
Support sorting items in the trade screens.
Caveat: sorts items in containers independently from the container.
Diffstat (limited to 'library/LuaWrapper.cpp')
-rw-r--r--library/LuaWrapper.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp
index 0b958f37..471dba64 100644
--- a/library/LuaWrapper.cpp
+++ b/library/LuaWrapper.cpp
@@ -446,6 +446,13 @@ Lua::ObjectClass Lua::IsDFObject(lua_State *state, int val_index)
return ok ? cls : Lua::OBJ_INVALID;
}
+static const char *const primitive_types[] = {
+ "string", NULL
+};
+static type_identity *const primitive_identities[] = {
+ df::identity_traits<std::string>::get(), NULL
+};
+
/**
* Given a DF object reference or type, safely retrieve its identity pointer.
*/
@@ -453,6 +460,12 @@ type_identity *LuaWrapper::get_object_identity(lua_State *state, int objidx,
const char *ctx, bool allow_type,
bool keep_metatable)
{
+ if (allow_type && !keep_metatable && lua_isstring(state, objidx))
+ {
+ int idx = luaL_checkoption(state, objidx, NULL, primitive_types);
+ return primitive_identities[idx];
+ }
+
if (!lua_getmetatable(state, objidx))
luaL_error(state, "Invalid object in %s", ctx);