コード例 #1
0
ファイル: sdl_core.cpp プロジェクト: admdly/CorsixTH
static int l_init(lua_State *L)
{
    Uint32 flags = 0;
    int i;
    int argc = lua_gettop(L);
    for(i = 1; i <= argc; ++i)
    {
        const char* s = luaL_checkstring(L, i);
        if(stricmp(s, "video") == 0)
            flags |= SDL_INIT_VIDEO;
        else if(stricmp(s, "audio") == 0)
            flags |= SDL_INIT_AUDIO;
        else if(stricmp(s, "timer") == 0)
            flags |= SDL_INIT_TIMER;
        else if(stricmp(s, "*") == 0)
            flags |= SDL_INIT_EVERYTHING;
        else
            luaL_argerror(L, i, "Expected SDL part name");
    }
    if(SDL_Init(flags) != 0)
    {
        std::fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
        lua_pushboolean(L, 0);
        return 1;
    }

    luaT_addcleanup(L, SDL_Quit);
    lua_pushboolean(L, 1);
    return 1;
}
コード例 #2
0
ファイル: sdl_audio.cpp プロジェクト: AtlasRedux/CorsixTH
static int l_init(lua_State *L)
{
    if(Mix_OpenAudio(luaL_optint(L, 1, MIX_DEFAULT_FREQUENCY),
        MIX_DEFAULT_FORMAT,
        luaL_optint(L, 2, MIX_DEFAULT_CHANNELS),
        luaL_optint(L, 3, 2048) /* chunk size */) != 0)
    {
        lua_pushboolean(L, 0);
        lua_pushstring(L, Mix_GetError());
        return 2;
    }
    else
    {
        lua_pushboolean(L, 1);
        luaT_addcleanup(L, Mix_CloseAudio);
        Mix_HookMusicFinished(audio_music_over_callback);
        return 1;
    }
}