[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua-SDL2 rc1 available for testing!
 
- From: Philipp Janda <siffiejoe@...>
 
- Date: Sat, 26 Apr 2014 16:41:47 +0200
 
Am 26.04.2014 12:38 schröbte David Demelier:
Hi there,
Hi!
I'm very happy to announce the first release candidate of Lua-SDL2
[1]. As I already announced a few
months ago, Lua-SDL2 is a pure C binding against SDL 2.0.3.
[...]
* A few functions are not implemented, it's the case of Texture:lock
for instance which is terribly
   hard to implement from Lua because the C side expect to cast the
pixel pointer to the underlyling
   sized array which in Lua is impossible to do. Please provide me
feedback on how you want it to
   be implemented.
That depends on what you want the Lua code to do with a locked texture. 
For my own binding I considered using something along the lines of
    myTexture:with_lock( function( modifypixels )
      -- code using the modifypixels function ...
    end )
but in the end I simply didn't implement direct access to pixel data in 
my binding (it has a rather narrow focus). `with_lock` would `pcall` 
(not `pcallk`![*]) the given function and pass a closure that has access 
to the pixel data and the pitch as argument. The Lua code would only 
access the pixel data via that function. After the `pcall` returns the 
upvalues of `modifypixels` get nil'ed using `lua_setupvalue` (for 
safety), and `SDL_UnlockTexture` is called before `with_lock` returns ...
* Feedback, provide me some enhancement you may find obvious or
better. In the code or in the documentation :-).
I don't know if that's intended, but your binding is rather low-level: 
It can crash in certain situations (e.g. if a renderer is collected 
before its textures, or window before renderer, etc.), and it would be 
easy to call `SDL_Quit` automatically via garbage-collection so that the 
binding doesn't leak if there is a non-local exit (e.g. an error, or a 
yielded coroutine that gets collected). Another minor point: If 
`lua_newuserdata` ever raises an error you will leak the corresponding 
SDL object.
Aside from that it looks very good (and I probably would have used it 
instead of rolling my own if had known about it a week ago)!
Enjoy this binding :-).
Kind regards,
David.
Philipp
  [*]: This is one of those rare cases where you *don't* want a 
yieldable `pcall` ...