Hi. Thanks for building SDLFW, it's really impressive.
As a learning project, I'm trying to translate from lft's klamrisk hero (http://www.linusakesson.net/games/klamrisk/index.php) from C/SDL to Lua/SDLFW.
I see that SDLFW_CreateAudioSpec initializes the callback parameter to SDLFW_mixaudio.
And I see that in lua_SDL_AudioSpec__index, the clause dealing with callback is commented out.
~~~~~~~~~~~~~~~~~~~
::::::::::C
APIint lua_SDL_AudioSpec__index( lua_State L )
{
lua_SDL_AudioSpec ud = (lua_SDL_AudioSpec ) lua_touserdata( L, 0x1 );
if ( !strcmp(lua_tostring(L, 0x2), "freq") )
{
lua_pushnumber( L, (lua_Number) ud -> val.freq );
}
else if ( !strcmp(lua_tostring(L, 0x2), "format") )
{
lua_pushnumber( L, (lua_Number) ud -> val.format );
}
else if ( !strcmp(lua_tostring(L, 0x2), "channels") )
{
lua_pushnumber( L, (lua_Number) ud -> val.channels );
}
else if ( !strcmp(lua_tostring(L, 0x2), "silence") )
{
lua_pushnumber( L, (lua_Number) ud -> val.silence );
}
else if ( !strcmp(lua_tostring(L, 0x2), "samples") )
{
lua_pushnumber( L, (lua_Number) ud -> val.samples );
}
else if ( !strcmp(lua_tostring(L, 0x2), "padding") )
{
lua_pushnumber( L, (lua_Number) ud -> val.padding );
}
else if ( !strcmp(lua_tostring(L, 0x2), "size") )
{
lua_pushnumber( L, (lua_Number) ud -> val.size );
}
/ else if ( !strcmp(lua_tostring(L, 0x2), "callback") )
{
lua_pushlightuserdata( L, ud -> val.callback );
} */
else if ( !strcmp(lua_tostring(L, 0x2), "userdata") )
{
lua_pushlightuserdata( L, ud -> val.userdata );
};
return 0x1;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is there an obstacle (or rather, would you please describe the obstacle) to uncommenting it, and scribbling audio buffers using lua callback functions?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SDLFW has your own internal callback (SDLFW_mixaudio) because this is more easy to implement and I don't know how to implement callbacks in Lua.
Please if do you know how to implement this callback in Lua, Can you tell me how I do to implement this feature to provide this in the new versions of SDLFW?
Last edit: CorEduard 2013-12-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure, but I think you need to use luaL_ref in that commented-out clause of ua_SDL_AudioSpec__index to make sure the lua function is not garbage collected. Then you'd have to store the int that luaL_ref returns somewhere. Then you'd have to change the ud's callback to a different C function. This new C callback would use lua_rawgeti(L, LUA_REGISTRYINDEX, <int>) to fetch the the lua callback onto the lua stack, and then call it.
View and moderate all "Questions" comments posted by this user
Mark all as spam, and block user from posting to "Forum"
Hi. Thanks for building SDLFW, it's really impressive.
As a learning project, I'm trying to translate from lft's klamrisk hero (http://www.linusakesson.net/games/klamrisk/index.php) from C/SDL to Lua/SDLFW.
I see that SDLFW_CreateAudioSpec initializes the callback parameter to SDLFW_mixaudio.
~~~~~~~~~~~~~~~~~~~~
:::::::::::C
SDL_AudioSpec APICALL SDLFW_CreateAudioSpec( void )
{
SDL_AudioSpec Spec;
Spec.freq = 0x0;
Spec.format = 0x0;
Spec.channels = 0x0;
Spec.silence = 0x0;
Spec.samples = 0x0;
Spec.padding = 0x0;
Spec.size = 0x0;
Spec.callback = SDLFW_mixaudio;
Spec.userdata = NULL;
return Spec;
}
~~~~~~~~~~~~~~~~~~~~~
And I see that in lua_SDL_AudioSpec__index, the clause dealing with callback is commented out.
~~~~~~~~~~~~~~~~~~~
::::::::::C
APIint lua_SDL_AudioSpec__index( lua_State L )
{
lua_SDL_AudioSpec ud = (lua_SDL_AudioSpec ) lua_touserdata( L, 0x1 );
if ( !strcmp(lua_tostring(L, 0x2), "freq") )
{
lua_pushnumber( L, (lua_Number) ud -> val.freq );
}
else if ( !strcmp(lua_tostring(L, 0x2), "format") )
{
lua_pushnumber( L, (lua_Number) ud -> val.format );
}
else if ( !strcmp(lua_tostring(L, 0x2), "channels") )
{
lua_pushnumber( L, (lua_Number) ud -> val.channels );
}
else if ( !strcmp(lua_tostring(L, 0x2), "silence") )
{
lua_pushnumber( L, (lua_Number) ud -> val.silence );
}
else if ( !strcmp(lua_tostring(L, 0x2), "samples") )
{
lua_pushnumber( L, (lua_Number) ud -> val.samples );
}
else if ( !strcmp(lua_tostring(L, 0x2), "padding") )
{
lua_pushnumber( L, (lua_Number) ud -> val.padding );
}
else if ( !strcmp(lua_tostring(L, 0x2), "size") )
{
lua_pushnumber( L, (lua_Number) ud -> val.size );
}
/ else if ( !strcmp(lua_tostring(L, 0x2), "callback") )
{
lua_pushlightuserdata( L, ud -> val.callback );
} */
else if ( !strcmp(lua_tostring(L, 0x2), "userdata") )
{
lua_pushlightuserdata( L, ud -> val.userdata );
};
return 0x1;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is there an obstacle (or rather, would you please describe the obstacle) to uncommenting it, and scribbling audio buffers using lua callback functions?
SDLFW has your own internal callback (SDLFW_mixaudio) because this is more easy to implement and I don't know how to implement callbacks in Lua.
Please if do you know how to implement this callback in Lua, Can you tell me how I do to implement this feature to provide this in the new versions of SDLFW?
Last edit: CorEduard 2013-12-29
View and moderate all "Questions" comments posted by this user
Mark all as spam, and block user from posting to "Forum"
I'm not sure, but I think you need to use luaL_ref in that commented-out clause of ua_SDL_AudioSpec__index to make sure the lua function is not garbage collected. Then you'd have to store the int that luaL_ref returns somewhere. Then you'd have to change the ud's callback to a different C function. This new C callback would use lua_rawgeti(L, LUA_REGISTRYINDEX, <int>) to fetch the the lua callback onto the lua stack, and then call it.
http://stackoverflow.com/questions/12823934/storing-reference-to-lua-function-in-c
Sorry, I am a dilettante at lua bindings myself.
I'm sorry, I tried to implement the audio callback from Lua but no luck, maybe I get it in the future :(
Anyway I was making more testing the internal callback and worked fine and now you have too the SDL_mixer as better alternative.
So if you have any more issues, tell me please, I will try to fix them the more faster I can.
Last edit: CorEduard 2014-01-01