Imported some of the dynamiccore branch from love-experiments:

- Type names for love's Lua objects are specified as an argument to luax_register_type, rather than being statically defined in an array.

- luax_register_type takes a variable number of method array arguments, for registering superclass methods without copying them into the subclass' method array.

Also removed most of the header declarations for wrapper functions.
This commit is contained in:
Alex Szpakowski
2015-11-29 20:38:12 -04:00
parent 77998c707d
commit 2c4e713114
124 changed files with 251 additions and 1300 deletions
+2 -2
View File
@@ -58,7 +58,7 @@ int w_Decoder_getDuration(lua_State *L)
return 1;
}
static const luaL_Reg functions[] =
static const luaL_Reg w_Decoder_functions[] =
{
{ "getChannels", w_Decoder_getChannels },
{ "getBitDepth", w_Decoder_getBitDepth },
@@ -69,7 +69,7 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_decoder(lua_State *L)
{
return luax_register_type(L, SOUND_DECODER_ID, functions);
return luax_register_type(L, SOUND_DECODER_ID, "Decoder", w_Decoder_functions, nullptr);
}
} // sound
-4
View File
@@ -31,10 +31,6 @@ namespace sound
{
Decoder *luax_checkdecoder(lua_State *L, int idx);
int w_Decoder_getChannels(lua_State *L);
int w_Decoder_getBitDepth(lua_State *L);
int w_Decoder_getSampleRate(lua_State *L);
int w_Decoder_getDuration(lua_State *L);
extern "C" int luaopen_decoder(lua_State *L);
} // sound
+20 -20
View File
@@ -32,6 +32,25 @@ namespace sound
#define instance() (Module::getInstance<Sound>(Module::M_SOUND))
int w_newDecoder(lua_State *L)
{
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
int bufferSize = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
Decoder *t = nullptr;
luax_catchexcept(L,
[&]() { t = instance()->newDecoder(data, bufferSize); },
[&](bool) { data->release(); }
);
if (t == nullptr)
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
luax_pushtype(L, SOUND_DECODER_ID, t);
t->release();
return 1;
}
int w_newSoundData(lua_State *L)
{
SoundData *t = 0;
@@ -63,30 +82,11 @@ int w_newSoundData(lua_State *L)
return 1;
}
int w_newDecoder(lua_State *L)
{
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
int bufferSize = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
Decoder *t = nullptr;
luax_catchexcept(L,
[&]() { t = instance()->newDecoder(data, bufferSize); },
[&](bool) { data->release(); }
);
if (t == nullptr)
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
luax_pushtype(L, SOUND_DECODER_ID, t);
t->release();
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "newSoundData", w_newSoundData },
{ "newDecoder", w_newDecoder },
{ "newSoundData", w_newSoundData },
{ 0, 0 }
};
-2
View File
@@ -32,8 +32,6 @@ namespace love
namespace sound
{
int w_newSoundData(lua_State *L);
int w_newDecoder(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_sound(lua_State *L);
} // sound
+8 -13
View File
@@ -96,13 +96,8 @@ int w_SoundData_getSample(lua_State *L)
return 1;
}
static const luaL_Reg functions[] =
static const luaL_Reg w_SoundData_functions[] =
{
// Data
{ "getString", w_Data_getString },
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getChannels", w_SoundData_getChannels },
{ "getBitDepth", w_SoundData_getBitDepth },
{ "getSampleRate", w_SoundData_getSampleRate },
@@ -115,21 +110,21 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_sounddata(lua_State *L)
{
// The last argument pushes the type's metatable onto the stack.
int ret = luax_register_type(L, SOUND_SOUND_DATA_ID, functions, true);
int ret = luax_register_type(L, SOUND_SOUND_DATA_ID, "SoundData", w_Data_functions, w_SoundData_functions, nullptr);
luax_gettypemetatable(L, SOUND_SOUND_DATA_ID);
// Load and execute SoundData.lua, sending the metatable as an argument.
if (ret > 0)
if (lua_istable(L, -1))
{
luaL_loadbuffer(L, sounddata_lua, sizeof(sounddata_lua), "SoundData.lua");
lua_pushvalue(L, -2);
lua_call(L, 1, 0);
// Pop the metatable.
lua_pop(L, 1);
ret--;
}
// Pop the metatable.
lua_pop(L, 1);
return ret;
}
-7
View File
@@ -31,13 +31,6 @@ namespace sound
{
SoundData *luax_checksounddata(lua_State *L, int idx);
int w_SoundData_getChannels(lua_State *L);
int w_SoundData_getBitDepth(lua_State *L);
int w_SoundData_getSampleRate(lua_State *L);
int w_SoundData_getSampleCount(lua_State *L);
int w_SoundData_getDuration(lua_State *L);
int w_SoundData_setSample(lua_State *L);
int w_SoundData_getSample(lua_State *L);
extern "C" int luaopen_sounddata(lua_State *L);
} // sound