mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 17:15:21 +02:00
MetaDataRef: Add contains() and get() (#7214)
This commit is contained in:
@@ -51,6 +51,42 @@ MetaDataRef* MetaDataRef::checkobject(lua_State *L, int narg)
|
||||
|
||||
// Exported functions
|
||||
|
||||
// contains(self, name)
|
||||
int MetaDataRef::l_contains(lua_State *L)
|
||||
{
|
||||
MAP_LOCK_REQUIRED;
|
||||
|
||||
MetaDataRef *ref = checkobject(L, 1);
|
||||
std::string name = luaL_checkstring(L, 2);
|
||||
|
||||
Metadata *meta = ref->getmeta(false);
|
||||
if (meta == NULL)
|
||||
return 0;
|
||||
|
||||
lua_pushboolean(L, meta->contains(name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get(self, name)
|
||||
int MetaDataRef::l_get(lua_State *L)
|
||||
{
|
||||
MAP_LOCK_REQUIRED;
|
||||
|
||||
MetaDataRef *ref = checkobject(L, 1);
|
||||
std::string name = luaL_checkstring(L, 2);
|
||||
|
||||
Metadata *meta = ref->getmeta(false);
|
||||
if (meta == NULL)
|
||||
return 0;
|
||||
|
||||
std::string str;
|
||||
if (meta->getStringToRef(name, str)) {
|
||||
lua_pushlstring(L, str.c_str(), str.size());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get_string(self, name)
|
||||
int MetaDataRef::l_get_string(lua_State *L)
|
||||
{
|
||||
|
Reference in New Issue
Block a user