Re: [ANN] Lua-SDL2 rc1 available for testing!
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [ANN] Lua-SDL2 rc1 available for testing!
- From: David Demelier <demelier.david@...>
- Date: 2014年4月27日 08:46:52 +0200
On 26/04/2014 16:41, Philipp Janda wrote:
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 ...
That's a really interesting way of doing it :-).
* 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.
Ah I didn't know that the program crash is a renderer is destroyed
before textures. But I can easily fix that by keeping references until
the renderer is destroyed it "owns" a reference to the texture and may
not be collected. (It's also done in the SDL_net Set object which "owns"
sockets).
Yes, the binding is rather low-level, because I wanted it to be a SDL
binding and not a game engine :-). However it is still a bit higher
level than C with the object orientation and some other convenient stuff.
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)!
Thanks :-).
Enjoy this binding :-).
Kind regards,
David.
Philipp
[*]: This is one of those rare cases where you *don't* want a
yieldable `pcall` ...