MyNixOS website logo
Description

A binding library of minilight for Lua langauge.

This library provides a way to write minilight component in Lua language.

minilight-lua

Hackage MIT license

A binding library of minilight for Lua language.

NB: This package is in the very early stage.

What's this?

  • minilight is a SDL2-based graphics library, equipped with component system.
  • Lua is a lightweight interpreted language.

With this library, you can write a minilight component in Lua language.

Getting Started

See example directory. Main.hs is an entrypoint for minilight engine.

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 mainFile

    return ()

  mainloop :: MiniLoop ()
  mainloop = do
    ref <- view _events
    evs <- liftIO $ tryReadMVar ref

    let 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).
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<minilight.Figure> function globally. This function will be called from Haskell and the returned array will be rendered in the component.
Metadata

Version

0.2.1.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows