Hi! I'm trying to create a custom audio source in C using playdate->sound->channel->addCallbackSource
. I want to expose a class for controlling the sound source to Lua so that I can do something like:
chan = playdate.sound.channel.new()
gen = generator.new() -- C class exposed to Lua via playdate->lua->registerClass
src = gen:add(chan)
-- src is now a playdate.sound.source instance
I'm having trouble getting the SoundChannel
instance in C using playdate->lua->getArgObject
.
If I use playdate->lua->getArgType
, I can see that the type of the second argument is playdate.sound.channel
:
Generator *gen = pd->lua->getArgObject(1, "generator", NULL);
// works as expected. gen is non-NULL
const char *outClass;
enum LuaType type = pd->lua->getArgType(2, &outClass);
// outClass is "playdate.sound.channel"
// type is kTypeObject (8)
However, if I try to get a SoundChannel
pointer using the playdate.sound.channel
as the class type, I get a NULL pointer:
SoundChannel *channel = pd->lua->getArgObject(2, "playdate.sound.channel", NULL);
// channel = NULL
Am I doing something wrong? Does the Playdate C API support this usage pattern?
Thanks!