Skip to content
Permalink
Browse files

Use C++ arrays for sdl->lua function reg

  • Loading branch information...
TheCycoONE committed Apr 22, 2019
1 parent 2f27a02 commit f4e6ee0c2d8d92d29fb3f3b3106e77ce85a835ae
Showing with 11 additions and 9 deletions.
  1. +7 −6 CorsixTH/Src/sdl_audio.cpp
  2. +4 −3 CorsixTH/Src/sdl_wm.cpp
@@ -30,6 +30,7 @@ SOFTWARE.
#pragma comment(lib, "SDL2_mixer")
#endif
#include <cstring>
#include <array>

class music
{
@@ -232,13 +233,13 @@ int l_transcode_xmi(lua_State *L)
return 1;
}

const struct luaL_Reg sdl_audiolib[] = {
constexpr std::array<struct luaL_Reg, 3> sdl_audiolib {{
{"init", l_init},
{"transcodeXmiToMid", l_transcode_xmi},
{nullptr, nullptr}
};
}};

const struct luaL_Reg sdl_musiclib[] = {
constexpr std::array<struct luaL_Reg, 8> sdl_musiclib {{
{"loadMusic", l_load_music},
{"loadMusicAsync", l_load_music_async},
{"playMusic", l_play_music},
@@ -247,7 +248,7 @@ const struct luaL_Reg sdl_musiclib[] = {
{"resumeMusic", l_resume_music},
{"setMusicVolume", l_music_volume},
{nullptr, nullptr}
};
}};

} // namespace

@@ -307,7 +308,7 @@ int l_load_music_async_callback(lua_State *L)
int luaopen_sdl_audio(lua_State *L)
{
lua_newtable(L);
luaT_setfuncs(L, sdl_audiolib);
luaT_setfuncs(L, sdl_audiolib.data());
lua_pushboolean(L, 1);
lua_setfield(L, -2, "loaded");

@@ -320,7 +321,7 @@ int luaopen_sdl_audio(lua_State *L)
lua_pushvalue(L, 1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
luaT_setfuncs(L, sdl_musiclib);
luaT_setfuncs(L, sdl_musiclib.data());

return 1;
}
@@ -28,6 +28,7 @@ SOFTWARE.
#include <SDL_syswm.h>
#include "../resource.h"
#endif
#include <array>

namespace {

@@ -61,18 +62,18 @@ int l_show_cursor(lua_State *L)
return 0;
}

const struct luaL_Reg sdl_wmlib[] = {
constexpr std::array<struct luaL_Reg, 3> sdl_wmlib {{
{"setIconWin32", l_set_icon_win32},
{"showCursor", l_show_cursor},
{nullptr, nullptr}
};
}};

} // namespace

int luaopen_sdl_wm(lua_State *L)
{
lua_newtable(L);
luaT_setfuncs(L, sdl_wmlib);
luaT_setfuncs(L, sdl_wmlib.data());

return 1;
}

0 comments on commit f4e6ee0

Please sign in to comment.
You can’t perform that action at this time.