Beispiel #1
0
String RemoveTrailingSlash(const String& pathName)
{
    String ret = pathName.Trimmed();
    ret.Replace('\\', '/');
    if (!ret.Empty() && ret.Back() == '/')
        ret.Resize(ret.Length() - 1);
    return ret;
}
Beispiel #2
0
String AddTrailingSlash(const String& pathName)
{
    String ret = pathName.Trimmed();
    ret.Replace('\\', '/');
    if (!ret.Empty() && ret.Back() != '/')
        ret += '/';
    return ret;
}
Beispiel #3
0
void LuaScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnSetAttribute(attr, src);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Set") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If set function exist
    if (function)
    {
        if (function->BeginCall(this))
        {
            function->PushVariant(src);
            function->EndCall();
        }
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());

        switch (attr.type_)
        {
        case VAR_BOOL:
            lua_pushboolean(luaState_, src.GetBool());
            break;
        case VAR_FLOAT:
            lua_pushnumber(luaState_, src.GetFloat());
            break;
        case VAR_STRING:
            tolua_pushurho3dstring(luaState_, src.GetString());
            break;
        case VAR_VECTOR2:
        {
            Vector2* value = new Vector2(src.GetVector2());
            tolua_pushusertype(luaState_, value, "Vector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR3:
        {
            Vector3* value = new Vector3(src.GetVector3());
            tolua_pushusertype(luaState_, value, "Vector3");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR4:
        {
            Vector4* value = new Vector4(src.GetVector4());
            tolua_pushusertype(luaState_, value, "Vector4");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_QUATERNION:
        {
            Quaternion* value = new Quaternion(src.GetQuaternion());
            tolua_pushusertype(luaState_, value, "Quaternion");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }

        break;
        case VAR_COLOR:
        {
            Color* value = new Color(src.GetColor());
            tolua_pushusertype(luaState_, value, "Color");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTRECT:
        {
            IntRect* value = new IntRect(src.GetIntRect());
            tolua_pushusertype(luaState_, value, "IntRect");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTVECTOR2:
        {
            IntVector2* value = new IntVector2(src.GetIntVector2());
            tolua_pushusertype(luaState_, value, "IntVector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        default:
            LOGERROR("Unsupported data type");
            lua_settop(luaState_, top);
            return;
        }

        lua_settable(luaState_, -3);
    }

    lua_settop(luaState_, top);
}
Beispiel #4
0
void LuaScriptInstance::OnGetAttribute(const AttributeInfo& attr, Variant& dest) const
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnGetAttribute(attr, dest);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Get") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If get function exist
    if (function)
    {
        if (function->BeginCall(this))
            function->EndCall(1);
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());
        lua_gettable(luaState_, -2);
    }

    switch (attr.type_)
    {
    case VAR_BOOL:
        dest = lua_toboolean(luaState_, -1) != 0;
        break;
    case VAR_FLOAT:
        dest = (float)lua_tonumber(luaState_, -1);
        break;
    case VAR_STRING:
        dest = tolua_tourho3dstring(luaState_, -1, "");
        break;
    case VAR_VECTOR2:
        dest = *((Vector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR3:
        dest = *((Vector3*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR4:
        dest = *((Vector4*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_QUATERNION:
        dest = *((Quaternion*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_COLOR:
        dest = *((Color*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTRECT:
        dest = *((IntRect*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTVECTOR2:
        dest = *((IntVector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    default:
        LOGERROR("Unsupported data type");
        return;
    }

    lua_settop(luaState_, top);
}
Beispiel #5
0
static void OVRRemoveTrailingNewlines(String& s)
{
    while(!s.IsEmpty() && ((s.Back() == '\n') || (s.Back() == '\r')))
        s.PopBack();
}