natiny.window.bind
natiny.window.bind(win [, fn])
Binds a window as the render target until it is unbound or replaced. With a callback, the window is unbound after the callback returns.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
win |
number |
Window handle from natiny.window.create |
|
fn |
function |
nil |
Callback whose draws target this window |
Example
natiny.window.bind(win, function()
draw_frame()
end)
Notes
- Rebinding the same window inside one
natiny.backend.loopcallback preserves its earlier draws. The accumulated image is presented after the callback. - Binding the window that is already bound, from inside that bind, does nothing, and the unbind that pairs with it does nothing either. A program that binds its window in its loop and again inside whatever the loop calls is saying "draw here" about the place it is already drawing, so the surfaces open under it stay open - and a game written that way can be handed a surface to draw on instead of the window without a line of it changing.
- With
fn, Lua unbinds the window even if the callback raises an error, then propagates the error.