lua-nanovg is a Lua binding library for NanoVG and NanoSVG.
It runs on OSX, GNU/Linux and on Windows (MSYS2/MinGW) and requires Lua (>=5.3) and GLFW (>=3.1).
Author: Xavier Wang
MIT/X11 license (same as Lua). See LICENSE.
See the Reference Manual.
Setup the build environment as described here, then:
$ git clone https://github.com/starwing/lua-nanovg
$ git submodule init
$ git submodule update
$ cd lua-nanovg
lua-nanovg$ make
lua-nanovg$ make install # or 'sudo make install' (Ubuntu)
-- Script: hello.lua
local nvg = require "nvg"
local glfw = require("moonglfw")
-- Allocate a window and deal with OpenGL
w = glfw.create_window(640, 480, "Hello world!")
glfw.make_context_current(w)
-- Only after this we can use nanovg
local canvas = nvg.new "antialias"
-- Repeatedly poll for events:
while not glfw.window_should_close(w) do
if glfw.get_key(w, "escape") == 'press' then break end
t = glfw.get_time()
ww, wh = glfw.get_window_size(w)
mx, my = glfw.get_cursor_pos(w)
local pw, _ = glfw.get_framebuffer_size(w)
local ratio = pw/ww
canvas:beginFrame(ww, wh, ratio)
canvas:clear "#4C4C51"
canvas:roundedRect((ww-320)/2, (wh-240)/2, 320, 240, 3)
canvas.fillStyle = "rgba(128,30,34,100)"
canvas:fill()
canvas:endFrame()
glfw.swap_buffers(w)
glfw.poll_events()
end
The script can be executed at the shell prompt with the standard Lua interpreter:
$ lua hello.lua
Other examples can be found in the examples/ directory contained in the release package.