Ejemplo n.º 1
0
void
Meta::setArray(const std::string &name, const std::vector<std::string> &value) {
    TypedValue val = TypedValue::createArrayValue();
    for (std::vector<std::string>::const_iterator it = value.begin();
         it != value.end();
         ++it) {
        val.add(StringUtils::EMPTY_STRING, TypedValue(*it));
    }
    setTypedValue(name, val);
}
Ejemplo n.º 2
0
void
Meta::setMap(const std::string &name, const std::vector<StringUtils::NamedValue> &value) {
    TypedValue val = TypedValue::createMapValue();
    for (std::vector<StringUtils::NamedValue>::const_iterator it = value.begin();
         it != value.end();
         ++it) {
        val.add(it->first, TypedValue(it->second));
    }
    setTypedValue(name, val);
}
Ejemplo n.º 3
0
static TypedValue
luaReadTableInternal(lua_State *lua, int index) {
    lua_pushnil(lua);
    TypedValue value = TypedValue::createArrayValue();
    bool is_map  = false;
    bool is_first  = true;
    while (lua_next(lua, index)) {
        if (is_first) {
            is_first = false;
            is_map = !lua_isnumber(lua, -2);
            if (is_map) {
                value = TypedValue::createMapValue();
            }
        }
        std::string key;
        if (is_map) {
            key.assign(lua_tostring(lua, -2));
        }
        switch (lua_type(lua, -1)) {
            case LUA_TNIL:
                value.add(key, TypedValue());
                break;
            case LUA_TBOOLEAN:
                value.add(key, TypedValue(0 != lua_toboolean(lua, -1)));
                break;
            case LUA_TNUMBER: {
                double d = lua_tonumber(lua, -1);
                isLongInteger(d) ? value.add(key, TypedValue((boost::int64_t)d)) :
                    value.add(key, TypedValue(d));
                break;
            }
            case LUA_TSTRING:
                value.add(key, TypedValue(std::string(lua_tostring(lua, -1))));
                break;
            case LUA_TTABLE:
                value.add(key, luaReadTableInternal(lua, lua_gettop(lua)));
                break;
            default:
                throw BadType("nil, bool, number, string or table", -1);
        }
        lua_pop(lua, 1);
    }
    return value;
}