赛派号

绞肉机苏泊尔还是小熊耐用 Web (and web

Web (and web-like) development with LuaRyan RionRyan Rion2 min read·Apr 28, 2016

--

One of the newest “big things” is building a web application. People want their applications accessible no matter what the platform in an easy-to-learn format. However, sometimes web developers don’t like working with just JaScript. Sometimes, you’ll want something more fun such as Lua. This guide will help you write an Electron.js (Electron Shell, used for software such as Tofino, Atom, and Visual Studio Code) or web application using Lua as an assistant. Here is a link to the Lua.vm.js GitHub repository..

Website Application using Lua.vm.js “Web” version

Building an app using Lua is as simple as loading the Lua.vm.js web version and building a for it. Example below.

js.global:alert("Heyyyyyyyyy") Web-based Application using Node.js, Electron.js, and Lua.vm.js

This is not intended as an Electron tutorial, only how to use Lua with Electron or Node.js

Building an Electron application is a bit more difficult because you’ll need to install the Node.js version; however, using Node.js, you can install both Lua.vm.js and Electron.js in two simple commands.

$ npm install lua.vm.js$ sudo npm install electron-prebuilt -g

Installing Electron.js in a global location allows for it to be automatically added into your path; if you would like to instead run Electron from the current location:

$ npm install electron-prebuilt$ PATH="$(npm bin):$PATH" electron

Using this local format can be written as a simple sh function:

npm-exec() { PATH="$(npm bin):$PATH" $*}

This way, you can run `npm-exec electron` and even if you he it installed locally it’ll run Electron.

To use Lua inside of your Node.js project, you need to load the VM, create a new Lua state, and execute some code.

var LuaVM = require("lua.vm.js"); // Load Lua VMvar L = new LuaVM.Lua.State(); // Create new Lua stateL.execute('print("Hello World!")'); // Execute Lua code

To execute Lua code, you would need to load the file in Node.js, read all of the code, and pass it to the Lua state’s execute function. Alternatively, you could put the Lua code inside of the loaded HTML file like the above example.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lsinopec@gmail.com举报,一经查实,本站将立刻删除。

上一篇 没有了

下一篇没有了