Getting audio capture callback in Lua

swolekat

New Member
Hello,

I'm trying to write a lua script to move a source based on the audio level of an audio source. I am currently trying to get the audio levels by setting up ` obs_source_add_audio_capture_callback` (https://obsproject.com/docs/referen...ure_t#c.obs_source_add_audio_capture_callback ). In lua I pass in a function as the second parameter and I get this error:

```
[audio-to-move.lua] Error calling script_load: E:/gitRepositiories/obs-scripts/src/audio-to-move.lua:67: Error in obs_source_add_audio_capture_callback (arg 2), expected 'obs_source_audio_capture_t' got 'function'
```

Is there something special I need to do to get this function to work? I'm a bit new to lua but I couldn't see any way to coerce it to the correct type.

I've uploaded my script to here: https://github.com/swolekat/obs-scripts/blob/main/src/audio-to-move.lua#L68
 
The Lua wrappers generated for the C functions in OBS can handle many common datatypes, but they can't cope with some "fancy" datatypes, and I suspect that is what you are seeing here.

Some such functions have had Lua (and/or Python) wrappers manually written, in order to bridge the gap between C (lotsa pointers, **, ...) and Lua (multiple return values, ...)
 

swolekat

New Member
Ah that makes sense. I was getting the sneaky feeling that I'd need to write it as a plugin in C. Thanks!
 
Top