-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API functions with pointer-pointer arguments are not usable in Lua #3462
Comments
@bfxdev I've found a forum post which uses ffi in LuaJIT to enumerate script properties using |
Good find @upgradeQ ! This is exactly the kind of solution I mentioned in the conclusion of my last post. But I was not aware that somebody already did it in OBS. I will try this. Of course it brings us very far from the original obslua bindings. |
Hello, I'm bumping this old thread because I didn't find a solution to that issue yet. I there still no way to retrieve the potential error string generated by It is really super tough to debug faulty hlsl shaders and I'm looking at anything that could make it easier. |
Platform
Operating system and version: Windows 10 Pro 1909
OBS Studio version: 25.0 and 26RC2, 32 bits and 64 bits
All platforms and versions are probably affected.
Expected Behavior
It should be possible to use all arguments of functions such as
gs_effect_create
orgs_texture_map
, which are exported to the obslua module and officially documented.Current Behavior
The issue affects those functions with pointer arguments that will typically receive the address of an existing buffer or a newly allocated memory area (to be freed later on).
For
gs_effect_t *gs_effect_create(const char *effect_string, const char *filename, char **error_string)
theerror_string
will be allocated with the results of the compilation. Only the valuenil
can be passed, passing e.g. an empty string results inexpected 'char **' got 'string'
.For
bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize)
, same kind of result, even the result oflinesize
cannot be retrieved (a simple pointer).Actually Lua does not support passing a string "by reference" (and strings are anyway not mutable). Either a mutable userdata object could be passed to receive the data, or the function needs to return an additional value.
Steps to Reproduce
Use the provided Lua script to see the currenty behavior when using
gs_effect_create
on some (faulty on purpose) effect code and trying to provide a variable to retrieve theerror_string
:expected 'char **' got 'string'
test-pointer-pointer-arguments.zip
The example is only focusing on
gs_effect_create
but many other functions are affected.Additional information
The issue is not new apparently.
There may be a workaround without any change in the OBS codebase by using FFI. I looked for solutions but until now I could not get something working (no experience at all with SWIG and very short experience with Lua).
Here are the alternatives I think are feasible.
Alternative 1: additional return value
The most common solution in Lua seems to be to type-map the parameter as an OUTPUT and expect it as additional return value. There is no standard typemap in
typemaps.i
for the conversion to a string from achar **
, so one needs to be written.The allocation aspects may play a role as well. The interface
cstring.i
is not implemented for Lua, too bad because%cstring_output_allocate(parm, release)
seems to be the one needed in that case.Alternative 2: mutable userdata
We could imagine a new C structure mapped to userdata, like other obs_something objects, that can be passed as argument. The structure would hold the pointer to the buffer, and frees it when garbage collected. A type-map would be needed in the interface file anyway.
That would be my preferred solution. At least it would look like a classical usage of a parameter passed by reference. No extra documentation necessary.
Other affected API functions
List of the functions that should be affected by the issue in Lua, according to a search in the
build\deps\obs-scripting\obslua\CMakeFiles\obslua.dir\obsluaLUA_wrap.c
file, generated during compilation (looking for calls toSWIG_isptrtype
with a pointer-pointer type):The text was updated successfully, but these errors were encountered: