Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.
ISC License
383 stars 73 forks source link

Fix: correct rwops read argument and return value #81

Closed hishamhm closed 3 years ago

hishamhm commented 5 years ago

As per https://github.com/Tangent128/luasdl2/wiki/Sdl-RWCreate, The Lua API for LuaSDL expects the Lua callback to have as inputs:

and it expects two returns

However, as per /usr/include/SDL2/SDL_rwops.h, the C API for SDL is different: it expects the C callback to use input arguments in reverse order:

and it expects a different return:

When size is different than 1, the number of items and bytes don't match. This causes problems when trying to use mixer.loadWAV_RW, which does perform calls with size greater than 1.

This commits fixes the behavior of the callback created via Lua.

Since this operation only ever worked correctly when size was 1, reversing the argument order declaration to match the C library is not a compatibility issue -- this just reflects correctly how the function really works.

markand commented 3 years ago

Thanks for the patch!