本文整理汇总了C++中NodeMetadata::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeMetadata::setString方法的具体用法?C++ NodeMetadata::setString怎么用?C++ NodeMetadata::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeMetadata
的用法示例。
在下文中一共展示了NodeMetadata::setString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_from_table
// from_table(self, table)
int NodeMetaRef::l_from_table(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeMetaRef *ref = checkobject(L, 1);
int base = 2;
// clear old metadata first
ref->m_env->getMap().removeNodeMetadata(ref->m_p);
if(lua_isnil(L, base)){
// No metadata
lua_pushboolean(L, true);
return 1;
}
// Create new metadata
NodeMetadata *meta = getmeta(ref, true);
if(meta == NULL){
lua_pushboolean(L, false);
return 1;
}
// Set fields
lua_getfield(L, base, "fields");
int fieldstable = lua_gettop(L);
lua_pushnil(L);
while(lua_next(L, fieldstable) != 0){
// key at index -2 and value at index -1
std::string name = lua_tostring(L, -2);
size_t cl;
const char *cs = lua_tolstring(L, -1, &cl);
std::string value(cs, cl);
meta->setString(name, value);
lua_pop(L, 1); // removes value, keeps key for next iteration
}
// Set inventory
Inventory *inv = meta->getInventory();
lua_getfield(L, base, "inventory");
int inventorytable = lua_gettop(L);
lua_pushnil(L);
while(lua_next(L, inventorytable) != 0){
// key at index -2 and value at index -1
std::string name = lua_tostring(L, -2);
read_inventory_list(L, -1, inv, name.c_str(), getServer(L));
lua_pop(L, 1); // removes value, keeps key for next iteration
}
reportMetadataChange(ref);
lua_pushboolean(L, true);
return 1;
}
示例2: l_set_float
// set_float(self, name, var)
int NodeMetaRef::l_set_float(lua_State *L)
{
NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
float a = lua_tonumber(L, 3);
std::string str = ftos(a);
NodeMetadata *meta = getmeta(ref, true);
if(meta == NULL || str == meta->getString(name))
return 0;
meta->setString(name, str);
reportMetadataChange(ref);
return 0;
}
示例3: l_set_string
// set_string(self, name, var)
int NodeMetaRef::l_set_string(lua_State *L)
{
NodeMetaRef *ref = checkobject(L, 1);
std::string name = luaL_checkstring(L, 2);
size_t len = 0;
const char *s = lua_tolstring(L, 3, &len);
std::string str(s, len);
NodeMetadata *meta = getmeta(ref, !str.empty());
if(meta == NULL || str == meta->getString(name))
return 0;
meta->setString(name, str);
reportMetadataChange(ref);
return 0;
}
示例4: l_set_int
// set_int(self, name, var)
int NodeMetaRef::l_set_int(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeMetaRef *ref = checkobject(L, 1);
std::string name = lua_tostring(L, 2);
int a = lua_tointeger(L, 3);
std::string str = itos(a);
NodeMetadata *meta = getmeta(ref, true);
if(meta == NULL || str == meta->getString(name))
return 0;
meta->setString(name, str);
reportMetadataChange(ref);
return 0;
}