zhaozg / lua-webview-1

Webview from Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

The Lua webview module provides functions to open a web page in a dedicated window from Lua.

require('webview').open('http://www.lua.org/')

It uses gtk-webkit2 on Linux and MSHTML (IE10/11) or Edge (Chromium) on Windows.

Lua can evaluate JavaScript code and JavaScript can call a registered Lua function, see the simple.lua file in the examples.

This module is a binding of the tiny cross-platform webview-c C library.

This module is part of the luaclibs project, the binaries can be found on the luajls page. You could also install it using LuaRocks.

Lua webview is covered by the MIT license.

Usage

Fast Cut allows to visually cut and join videos then export losslessly thanks to FFmpeg.

Launcher

An optional Lua launcher module webview-launcher.lua is available. The HTML scripts using the type text/lua will be loaded automatically. The Lua scripts could expose named functions with callbacks to JavaScript.

<button onclick="webview.sayHello('You', console.info)">Say Hello</button>
<script type="text/lua">
  context.exposeAll({
    sayHello = function(value, callback)
      callback(nil, 'Hello '..tostring(value))
    end
  })
</script>

or using a Lua file

<script src="assets/FileChooser.lua" type="text/lua"></script>

Additionally a JavaScript file webview-init.js is available to deal with the launcher initialization including in case of reloading.

The launcher supports events in Lua when used with luajls.

Examples

Using an HTTP server

lua examples/calc.lua

Using the file system

lua examples/open.lua %CD%\examples\htdocs\todo.html

Pure Lua

wlua53 examples/simple.lua

Generic launcher, with helper function to pass JSON objects and more

lua examples/launch.lua examples/htdocs/simple.html --wv-event=thread

LuaRocks

Lua webview can be intalled using LuaRocks

LuaRocks on Linux

Prerequisites:

sudo apt install luarocks lua5.3 lua5.3-dev
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev
luarocks install lua-webview --local

LuaRocks on Windows

Prerequisites: Download the Lua 64 bits dynamic libraries built with MinGW-w64 from Lua Binaries. Add MSYS2, MinGW-w64 and git in the path.

luarocks --lua-dir C:/bin/lua-5.3.5 MAKE=make CC=gcc LD=gcc install lua-webview

Take care to use forward slashes for the Lua path.

About

Webview from Lua

License:Other


Languages

Language:Lua 61.5%Language:C 28.7%Language:Makefile 7.2%Language:JavaScript 2.5%