Пример #1
0
static int l_load_toplevel(lua_State *L)
{
    size_t iDataLength;
    const uint8_t *pData = luaT_checkfile(L, 1, &iDataLength);
    luaL_checktype(L, 2, LUA_TTABLE);
    lua_settop(L, 2);
    lua_pushvalue(L, 1);
    LuaPersistBasicReader *pReader = new (lua_newuserdata(L, sizeof(LuaPersistBasicReader))) LuaPersistBasicReader(L);
    lua_replace(L, 1);
    pReader->init(pData, iDataLength);
    if(!pReader->readStackObject() || !pReader->finish())
    {
        int iNumObjects = (int)pReader->getObjectCount();
        int iNumBytes = (int)(pReader->getPointer() - pData);
        lua_pushnil(L);
        lua_pushfstring(L, "%s after %d objects (%d bytes)",
            pReader->getError() ? pReader->getError() : "Error while depersisting",
            iNumObjects, iNumBytes);
        return 2;
    }
    else
    {
        return 1;
    }
}
Пример #2
0
static int l_spritesheet_load(lua_State *L)
{
    THSpriteSheet* pSheet = luaT_testuserdata<THSpriteSheet>(L);
    size_t iDataLenTable, iDataLenChunk;
    const uint8_t* pDataTable = luaT_checkfile(L, 2, &iDataLenTable);
    const uint8_t* pDataChunk = luaT_checkfile(L, 3, &iDataLenChunk);
    bool bComplex = lua_toboolean(L, 4) != 0;
    THRenderTarget* pSurface = luaT_testuserdata<THRenderTarget>(L, 5, luaT_upvalueindex(1), false);

    if(pSheet->loadFromTHFile(pDataTable, iDataLenTable, pDataChunk, iDataLenChunk, bComplex, pSurface))
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);

    return 1;
}
Пример #3
0
static int l_load_strings(lua_State *L)
{
    size_t iDataLength;
    const unsigned char* pData = luaT_checkfile(L, 1, &iDataLength);

    THStringList oStrings;
    if(!oStrings.loadFromTHFile(pData, iDataLength))
    {
        lua_pushboolean(L, 0);
        return 1;
    }

    lua_settop(L, 0);
    lua_createtable(L, (int)oStrings.getSectionCount(), 0);
    for(unsigned int iSec = 0; iSec < oStrings.getSectionCount(); ++iSec)
    {
        unsigned int iCount = oStrings.getSectionSize(iSec);
        lua_createtable(L, (int)iCount, 0);
        for(unsigned int iStr = 0; iStr < iCount; ++iStr)
        {
            lua_pushstring(L, oStrings.getString(iSec, iStr));
            lua_rawseti(L, 2, (int)(iStr + 1));
        }
        lua_rawseti(L, 1, (int)(iSec + 1));
    }
    return 1;
}
Пример #4
0
static int l_freetype_font_set_face(lua_State *L)
{
    THFreeTypeFont* pFont = luaT_testuserdata<THFreeTypeFont>(L);
    size_t iLength;
    const uint8_t* pData = luaT_checkfile(L, 2, &iLength);
    lua_settop(L, 2);

    l_freetype_throw_error_code(L, pFont->setFace(pData, iLength));
    luaT_setenvfield(L, 1, "face");
    return 1;
}
Пример #5
0
static int l_palette_load(lua_State *L)
{
    THPalette* pPalette = luaT_testuserdata<THPalette>(L);
    size_t iDataLen;
    const uint8_t* pData = luaT_checkfile(L, 2, &iDataLen);

    if(pPalette->loadFromTHFile(pData, iDataLen))
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);
    return 1;
}
Пример #6
0
static int l_anims_load(lua_State *L)
{
    THAnimationManager* pAnims = luaT_testuserdata<THAnimationManager>(L);
    size_t iStartDataLength, iFrameDataLength, iListDataLength, iElementDataLength;
    const unsigned char* pStartData = luaT_checkfile(L, 2, &iStartDataLength);
    const unsigned char* pFrameData = luaT_checkfile(L, 3, &iFrameDataLength);
    const unsigned char* pListData = luaT_checkfile(L, 4, &iListDataLength);
    const unsigned char* pElementData = luaT_checkfile(L, 5, &iElementDataLength);

    if(pAnims->loadFromTHFile(pStartData, iStartDataLength, pFrameData, iFrameDataLength,
        pListData, iListDataLength, pElementData, iElementDataLength))
    {
        lua_pushboolean(L, 1);
    }
    else
    {
        lua_pushboolean(L, 0);
    }

    return 1;
}
Пример #7
0
static int l_soundarc_load(lua_State *L)
{
    THSoundArchive* pArchive = luaT_testuserdata<THSoundArchive>(L);
    size_t iDataLen;
    const unsigned char* pData = luaT_checkfile(L, 2, &iDataLen);

    if(pArchive->loadFromTHFile(pData, iDataLen))
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);
    return 1;
}
Пример #8
0
static int l_map_load(lua_State *L)
{
    THMap* pMap = luaT_testuserdata<THMap>(L);
    size_t iDataLen;
    const uint8_t* pData = luaT_checkfile(L, 2, &iDataLen);
    lua_settop(L, 2);
    lua_newtable(L);
    if(pMap->loadFromTHFile(pData, iDataLen, l_map_load_obj_cb, (void*)L))
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);
    lua_insert(L, -2);
    return 2;
}
Пример #9
0
static int l_rawbitmap_load(lua_State *L)
{
    THRawBitmap* pBitmap = luaT_testuserdata<THRawBitmap>(L);
    size_t iDataLen;
    const uint8_t* pData = luaT_checkfile(L, 2, &iDataLen);
    int iWidth = static_cast<int>(luaL_checkinteger(L, 3));
    THRenderTarget* pSurface = luaT_testuserdata<THRenderTarget>(L, 4, luaT_upvalueindex(1), false);

    if(pBitmap->loadFromTHFile(pData, iDataLen, iWidth, pSurface))
        lua_pushboolean(L, 1);
    else
        lua_pushboolean(L, 0);

    return 1;
}
Пример #10
0
static int l_transcode_xmi(lua_State *L)
{
    size_t iLength, iMidLength;
    const unsigned char *pData = luaT_checkfile(L, 1, &iLength);

    unsigned char *pMidData = TranscodeXmiToMid(pData, iLength, &iMidLength);
    if(pMidData == NULL)
    {
        lua_pushnil(L);
        lua_pushliteral(L, "Unable to transcode XMI to MIDI");
        return 2;
    }
    lua_pushlstring(L, (const char*)pMidData, iMidLength);
    delete[] pMidData;

    return 1;
}
Пример #11
0
/*!
    loadCustom(<data-of-an-animation-file>) -> true/false
 */
static int l_anims_loadcustom(lua_State *L)
{
    THAnimationManager* pAnims = luaT_testuserdata<THAnimationManager>(L);
    size_t iDataLength;
    const uint8_t* pData = luaT_checkfile(L, 2, &iDataLength);

    if (pAnims->loadCustomAnimations(pData, iDataLength))
    {
        lua_pushboolean(L, 1);
    }
    else
    {
        lua_pushboolean(L, 0);
    }

    return 1;
}
Пример #12
0
static int l_anims_set_alt_pal(lua_State *L)
{
    THAnimationManager* pAnims = luaT_testuserdata<THAnimationManager>(L);
    unsigned int iAnimation = luaL_checkint(L, 2);
    size_t iPalLen;
    const unsigned char *pPal = luaT_checkfile(L, 3, &iPalLen);
    if(iPalLen != 256)
        return luaL_typerror(L, 3, "GhostPalette string");

    pAnims->setAnimationAltPaletteMap(iAnimation, pPal);

    lua_getfenv(L, 1);
    lua_insert(L, 2);
    lua_settop(L, 4);
    lua_settable(L, 2);
    lua_settop(L, 1);
    return 1;
}
Пример #13
0
static int l_load_music(lua_State *L)
{
    size_t iLength;
    const uint8_t *pData = luaT_checkfile(L, 1, &iLength);
    SDL_RWops* rwop = SDL_RWFromConstMem(pData, (int)iLength);
    Mix_Music* pMusic = Mix_LoadMUS_RW(rwop, 1);
    if(pMusic == nullptr)
    {
        lua_pushnil(L);
        lua_pushstring(L, Mix_GetError());
        return 2;
    }
    music_t* pLMusic = luaT_stdnew<music_t>(L, luaT_environindex, true);
    pLMusic->pMusic = pMusic;
    lua_pushvalue(L, 1);
    luaT_setenvfield(L, -2, "data");
    return 1;
}
Пример #14
0
static int l_load_music_async(lua_State *L)
{
    size_t iLength;
    const uint8_t *pData = luaT_checkfile(L, 1, &iLength);
    luaL_checktype(L, 2, LUA_TFUNCTION);
    SDL_RWops* rwop = SDL_RWFromConstMem(pData, (int)iLength);
    lua_settop(L, 2);

    load_music_async_t *async = luaT_new(L, load_music_async_t);
    lua_pushlightuserdata(L, async);
    lua_pushvalue(L, -2);
    lua_settable(L, LUA_REGISTRYINDEX);
    async->L = L;
    async->music = nullptr;
    async->rwop = rwop;
    async->err = nullptr;
    lua_createtable(L, 2, 0);
    lua_pushthread(L);
    lua_rawseti(L, -2, 1);
    lua_pushvalue(L, 2);
    lua_rawseti(L, -2, 2);
    luaT_stdnew<music_t>(L, luaT_environindex, true);
    lua_pushvalue(L, 1);
    luaT_setenvfield(L, -2, "data");
    lua_rawseti(L, -2, 3);
    lua_settable(L, LUA_REGISTRYINDEX);

    /*
        In registry:
          [light userdata async] -> [full userdata async]
          [full userdata async] -> {
            [1] = callback_thread,
            [2] = callback_function,
            [3] = empty music_t userdata,
          }

        New thread will load music, and inform the main loop, which will then
        call the callback and remove the new entries from the registry.
    */

    SDL_CreateThread(load_music_async_thread, "music_thread", async);

    return 0;
}
Пример #15
0
static int l_anims_set_alt_pal(lua_State *L)
{
    THAnimationManager* pAnims = luaT_testuserdata<THAnimationManager>(L);
    size_t iAnimation = luaL_checkinteger(L, 2);
    size_t iPalLen;
    const uint8_t *pPal = luaT_checkfile(L, 3, &iPalLen);
    if(iPalLen != 256)
    {
        return luaL_argerror(L, 3, "GhostPalette string is not a valid palette");
    }
    uint32_t iAlt32 = static_cast<uint32_t>(luaL_checkinteger(L, 4));

    pAnims->setAnimationAltPaletteMap(iAnimation, pPal, iAlt32);

    lua_getfenv(L, 1);
    lua_insert(L, 2);
    lua_settop(L, 4);
    lua_settable(L, 2);
    lua_settop(L, 1);
    return 1;
}