https://github.com/myuon/minilight-lua
A binding library of minilight for Lua langauge
https://github.com/myuon/minilight-lua
haskell lua
Last synced: 3 months ago
JSON representation
A binding library of minilight for Lua langauge
- Host: GitHub
- URL: https://github.com/myuon/minilight-lua
- Owner: myuon
- License: mit
- Created: 2020-05-06T16:24:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-16T06:00:32.000Z (about 5 years ago)
- Last Synced: 2025-02-21T12:03:01.865Z (4 months ago)
- Topics: haskell, lua
- Language: Haskell
- Homepage:
- Size: 425 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# minilight-lua
[](https://hackage.haskell.org/package/minilight-lua) [](LICENSE)
A binding library of [minilight](https://github.com/myuon/minilight) for Lua language.
*NB: This package is in the very early stage.*
## What's this?
- [minilight](http://hackage.haskell.org/package/minilight) is a SDL2-based graphics library, equipped with component system.
- [Lua](https://www.lua.org) is a lightweight interpreted language.With this library, you can write a minilight component in Lua language.
## Getting Started
See [example](https://github.com/myuon/minilight-lua/tree/master/example) directory. `Main.hs` is an entrypoint for minilight engine.
```hs
mainFile = "example/main.lua"main :: IO ()
main = runLightT $ runMiniloop
(defConfig { hotConfigReplacement = Just "example", appConfigFile = Just "" })
initial
(const mainloop)
where
initial = do
comp <- registerComponent mainFile newLuaComponent
reload mainFilereturn ()
mainloop :: MiniLoop ()
mainloop = do
ref <- view _events
evs <- liftIO $ tryReadMVar reflet notifys = case evs of
Just evs -> mapMaybe asNotifyEvent evs
_ -> []
unless (null notifys) $ reload mainFile
```Some notes here:
- When you pass `hotConfigReplacement` field, minilight will watch the given directory and emits *file changed/created/delete* events during the mainloop.
- For `registerComponent` you need to pass the filename like `example/main.lua`. The path is relative where you run `cabal run`.
- In `mainloop`, watches any events and `reload` the component. The `reload` function will load the lua file again and swap the component dynamically (code swapping).```lua
local minilight = require("minilight")function onDraw()
print("[LUA OUTPUT] hello")return {
minilight.translate(50, 50, minilight.picture("example/example.png")),
minilight.translate(100, 100, minilight.text("こんにちは世界",
{0, 0, 0, 0})),
minilight.translate(30, 50,
minilight.text("Hello, World!", {255, 0, 0, 0}))
}
end_G.onDraw = onDraw
```For lua part:
- Require `minilight` library. This will be implicitly loaded by minilight-lua.
- You need to export `onDraw : () -> Array` function globally. This function will be called from Haskell and the returned array will be rendered in the component.