示例#1
0
static int GetProfile(lua_State * pLua) {
	if(lua_gettop(pLua) != 1) {
        luaL_error(pLua, "bad argument count to 'GetProfile' (1 expected, got %d)", lua_gettop(pLua));
        lua_settop(pLua, 0);
        lua_pushnil(pLua);
        return 1;
    }

    if(lua_type(pLua, 1) == LUA_TSTRING) {
        size_t szLen;
        char *profName = (char *)lua_tolstring(pLua, 1, &szLen);

        if(szLen == 0) {
        	lua_settop(pLua, 0);
            lua_pushnil(pLua);
            return 1;
        }

		int32_t idx = ProfileManager::m_Ptr->GetProfileIndex(profName);

        lua_settop(pLua, 0);

        if(idx == -1) {
            lua_pushnil(pLua);
            return 1;
        }

        PushProfile(pLua, (uint16_t)idx);
        return 1;
    } else if(lua_type(pLua, 1) == LUA_TNUMBER) {
#if LUA_VERSION_NUM < 503
		uint16_t idx = (uint16_t)lua_tonumber(pLua, 1);
#else
    	uint16_t idx = (uint16_t)lua_tointeger(pLua, 1);
#endif

    	lua_settop(pLua, 0);
    
        // if the requested index is out of bounds return nil
        if(idx >= ProfileManager::m_Ptr->m_ui16ProfileCount) {
            lua_pushnil(pLua);
            return 1;
        }
    
        PushProfile(pLua, idx);
        return 1;
    }

    luaL_error(pLua, "bad argument #1 to 'GetProfile' (string or number expected, got %d)", lua_typename(pLua, lua_type(pLua, 1)));
	lua_settop(pLua, 0);
	lua_pushnil(pLua);
    return 1;
}
示例#2
0
static int GetProfile(lua_State * L) {
	if(lua_gettop(L) != 1) {
        luaL_error(L, "bad argument count to 'GetProfile' (1 expected, got %d)", lua_gettop(L));
        lua_settop(L, 0);
        lua_pushnil(L);
        return 1;
    }

    if(lua_type(L, 1) == LUA_TSTRING) {
        size_t szLen;
        char *profName = (char *)lua_tolstring(L, 1, &szLen);

        if(szLen == 0) {
            lua_pushnil(L);
            return 1;
        }

		int32_t idx = ProfileMan->GetProfileIndex(profName);

        lua_settop(L, 0);

        if(idx == -1) {
            lua_pushnil(L);
            return 1;
        }

        PushProfile(L, (uint16_t)idx);
        return 1;
    } else if(lua_type(L, 1) == LUA_TNUMBER) {
    	uint16_t idx = (uint16_t)lua_tonumber(L, 1);

    	lua_settop(L, 0);
    
        // if the requested index is out of bounds return nil
        if(idx >= ProfileMan->iProfileCount) {
            lua_pushnil(L);
            return 1;
        }
    
        PushProfile(L, idx);
        return 1;
    } else {
        luaL_error(L, "bad argument #1 to 'GetProfile' (string or number expected, got %d)", lua_typename(L, lua_type(L, 1)));
		lua_settop(L, 0);
		lua_pushnil(L);
        return 1;
    }
}
示例#3
0
static int GetProfiles(lua_State * L) {
	if(lua_gettop(L) != 0) {
        luaL_error(L, "bad argument count to 'GetProfiles' (0 expected, got %d)", lua_gettop(L));
        lua_settop(L, 0);
        lua_pushnil(L);
        return 1;
    }

    lua_newtable(L);
    int t = lua_gettop(L);

    for(uint16_t ui16i = 0; ui16i < ProfileMan->iProfileCount; ui16i++) {
        lua_pushnumber(L, (ui16i+1));
        PushProfile(L, ui16i);
        lua_rawset(L, t);
    }

    return 1;
}
示例#4
0
static int GetProfiles(lua_State * pLua) {
	if(lua_gettop(pLua) != 0) {
        luaL_error(pLua, "bad argument count to 'GetProfiles' (0 expected, got %d)", lua_gettop(pLua));
        lua_settop(pLua, 0);
        lua_pushnil(pLua);
        return 1;
    }

    lua_newtable(pLua);
    int t = lua_gettop(pLua);

    for(uint16_t ui16i = 0; ui16i < ProfileManager::m_Ptr->m_ui16ProfileCount; ui16i++) {
#if LUA_VERSION_NUM < 503
		lua_pushnumber(pLua, (ui16i+1));
#else
        lua_pushinteger(pLua, (ui16i+1));
#endif

        PushProfile(pLua, ui16i);
        lua_rawset(pLua, t);
    }

    return 1;
}