Code Monkey home page Code Monkey logo

lua.js's Introduction

#Lua.js#

Lua.js is a great project that can convert lua code to javascript.

lua.js is fully written by javascript, so both lua.js self and all generated code can be run on web.

Try it on: Live Demo

Contact me with:

QQ: 402740419

E-mail: [email protected]

Usage

Build web version

Get Google Closure Compiler, copy compiler to lua.js directory. You need to install java(JRE).

Run buildweb.cmd on windows or write your own buildweb.sh for linux/mac

Use on html

<script type="application/x-lua">
	-- lua code here
</script>

Create other contexts

In javascript:

var L = luajs.newContext();
L.loadStdLib();
var f = L.loadString('print "Hello, Lua.js!"');
f();

In lua:

local L = luajs.newContext();
L.loadStdLib();
local f = L.loadString(js);
f();

Limitation

Coroutine will never be supported by lua.js

__mode and __gc in metatable was not supported by lua.js.

String pattern support is still on working.

Support

Thanks for support me by:

支付宝:###

支付宝

lua.js's People

Contributors

tdzl2003 avatar brollb avatar

Stargazers

Toby Lai avatar Yemdust avatar  avatar Agony avatar HuiHui avatar  avatar AILHC avatar AceLam avatar xiaoming.zhuang avatar XDC avatar  avatar  avatar Happy bull avatar Hai avatar  avatar  avatar  avatar 苏扬 avatar Zip.Wu avatar  avatar  avatar  avatar  avatar  avatar xxxxxxxxx_man avatar  avatar  avatar ig avatar yuliang avatar 吴铭 avatar Airclear avatar 吴聃聃 avatar  avatar BernieLiu avatar weimingtom avatar David Nishikaze avatar  avatar Xavier Wang avatar soda avatar Yanghe Sun avatar Henri avatar  avatar Federico Lucignano avatar smallwhite avatar Sergey Storchay avatar John Lee avatar Shaun Cheng avatar Ken Huang avatar Li, Xizhi avatar ljb avatar 许建波 avatar Paul G avatar 周家未 avatar Philip J Anders avatar Rekc@h avatar Lee avatar xqq avatar Morrow1nd avatar  avatar Rok Fajfar avatar 早晨海风 avatar  avatar  avatar yung avatar inking-cn avatar Jennal avatar  avatar Yukita Mayako avatar Vadim Peretokin avatar Qian Ye avatar Zeng avatar luwei avatar Wim Vander Schelden avatar detailyang avatar 文宇祥 avatar Conrad Steenberg avatar Zero avatar Thomas Kumlehn avatar Pablo Ariel Mayobre avatar  avatar Roland avatar Landon Manning avatar Arthur Stolyar avatar Yao avatar  avatar 西风逍遥游 avatar  avatar Paul Rumkin avatar ding huidong avatar  avatar  avatar  avatar Angus H. avatar Mikoláš Štrajt avatar buhe avatar  avatar Yu Zeng avatar StillSky avatar KOLANICH avatar Fabien Devaux avatar

Watchers

cc avatar soda avatar 吴铭 avatar  avatar  avatar Rok Fajfar avatar 许建波 avatar wzjmit avatar  avatar  avatar  avatar  avatar  avatar yao avatar telee6789 avatar  avatar  avatar 叶晓风 avatar Philip J Anders avatar 超級码力 avatar

lua.js's Issues

Issue with print

print(false) -- show 'nil' now, should be false
local  a = __js[[ [0,0,0] ]]
print(a[1]) -- show 'nil' now, should be 0

I will reconstruct lua.js very soon.

Target:

  1. Build with CommonJS, compatible with node.js/webpack/react native
  2. Solve upvalue-in-repeat issue. This breaks many people to use lua.js
  3. Performance improve because my JS level was up.
  4. Support missing grammar, hex integer etc..
  5. Unit Test, Travis-CI, blah blah..

Access to "helpers" from outside a LuaContext

It would be nice if there was a way to access the helpers object for a lua context to allow for detection/overriding methods like __set and __call in generated js code.

I would suggest adding __helpers to the LuaContext object when it is created.

string.byte not working

print(type(string.byte('aaa')))

This will print 'nil'.
Look at stdlib.lua, the function string.byte is missing a 'return' statement.

Upvalue in repeat block are same reference now.

local t = {}
for i = 1, 10 do
    t[i] = function()
       print(i)
    end
end

for i = 1, 10 do
    t[i]()
end

-- should print 1 to 10, but print 11s now.

local t = {}
for i = 1, 10 do
    local j = 0
    t[i] = function()
       j = j + 1
       print(j)
    end
end

for i = 1, 10 do
    t[i]()
end
-- should print 10 lines of  `1`, but print 1 to 10 now.

Bug for pairs

t={}
t.a = 0
t.b = 0
t.c = 0
t.d = 0
t.e = 0
t.b = 0
t.g = 0
for k, v in pairs(t) do
  print(k)
end

Output missing 'c', 'd', 'e'.

can this compile to readable js code

I am going to use this to convert a lua project to web+js application. Because of I am using the 3rd party framework I may need add more function according the framework's api, so is there any method to get this doen or any suggestion will be really appreciated, thanks.

Single script for node/browser

the build should create a script that works both in browser and node environments rather than just the browser.

I realize it can still be used in both contexts (by either using the generated script or lib/index.js) but it would be nice to be able to have a single script that can be used in either rather than requiring the scripts to be changed depending upon the execution environment

这段代码跑不了

local s = "aaa"
s:gsub(".", print)

这个代码跑了说:

Error: attempt to index a string value.

Testing framework

Tests should use a modern testing framework (such as mocha) so the tests are automatically verified (currently, they simply print the result to the console and are verified by the dev).

Issue with repeat-until block.

local b = 1

repeat
  local a = 1
  b = b + 1
  if (b == 3) then
      break
  end
until a==1
-- should be 2.
print("Here",b);

now report SyntaxError: Illegal break statement

and until a==1 do wrong thing compare with offical lua.

Support Scientific Notation

Currently, lua.js doesn't support setting values using scientific notation. For example:

x = 1e-6

runs using lua from cli but fails with lua.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.