Implemented efficient FFI versions of SoundData methods, which are used when the LuaJIT FFI and JIT compiler are present.

This commit is contained in:
Alex Szpakowski
2015-06-14 18:41:34 -03:00
parent 57fa9994af
commit 532c61c6c2
5 changed files with 165 additions and 18 deletions
+26 -1
View File
@@ -22,11 +22,21 @@
#include "common/wrap_Data.h"
// Shove the wrap_SoundData.lua code directly into a raw string literal.
static const char sounddata_lua[] =
#include "wrap_SoundData.lua"
;
namespace love
{
namespace sound
{
/**
* NOTE: Additional wrapper code is in wrap_SoundData.lua. Be sure to keep it
* in sync with any changes made to this file!
**/
SoundData *luax_checksounddata(lua_State *L, int idx)
{
return luax_checktype<SoundData>(L, idx, SOUND_SOUND_DATA_ID);
@@ -105,7 +115,22 @@ static const luaL_Reg functions[] =
extern "C" int luaopen_sounddata(lua_State *L)
{
return luax_register_type(L, SOUND_SOUND_DATA_ID, functions);
// The last argument pushes the type's metatable onto the stack.
int ret = luax_register_type(L, SOUND_SOUND_DATA_ID, functions, true);
// Load and execute SoundData.lua, sending the metatable as an argument.
if (ret > 0)
{
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--;
}
return ret;
}
} // sound