- // Has metadata; clear old one first
- ref->m_env->getMap().removeNodeMetadata(ref->m_p);
- // Create new metadata
- NodeMetadata *meta = getmeta(ref, true);
- // 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