GithubHelp home page GithubHelp logo

siathalysedi / ljs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mingodad/ljs

0.0 3.0 0.0 623 KB

Lua with C/C++/Java/Javascript syntax

License: MIT License

Makefile 1.08% C 95.51% LilyPond 1.56% Shell 0.04% Lua 0.47% C++ 1.33%

ljs's Introduction

ljs

Lua with C/C++/Java/Javascript syntax

Here is some code to see how it's like:

/* Limited json style table declaration */
var json = {"name": "bob"};
var A = {t: {f: 7}, n: 3}
var ary = [1,2,3,4]; //Array style declaration, syntax sugar for {}
var num = 5;

if(json.name == "bob") print("Hello Bob !"); // if/ese like in C/C++/Java/Javascript 
else if(json.name == "mary") print("A pretty woman !");
else print("Nice to meet you !");

for(i=1, 10) print(i);
for(k,v in pairs(json)) print(k,v);

for(k,v in pairs(A)) { // blocks are curly braces delimited
	if(k == "one") continue;
	print(k, type(k), v);
}

while(num > 0) --num; //pre inc/dec operators
num += 5; // compound operators
while(num > 0) {
	print(num--);
}
num += 5;
do { //conventional do/while
	if(num == 3) goto update;
	//inline boolean expression
	print(num == 2 ? "it's a two" : "it's a " .. num);
update:
	--num;
} while(num > 0);

function doIt(p : string) : string { // functions and variables can have an anotation
	return "Done " .. p;
}

print(doIt("car"));

function doAgain(p) {
	if(p == null) return "I don't know what to do !"; // uses "null" instead of "nil"
	return "Done " .. p;
}

print(doAgain("car"));

var Engine = {
	speed : 0
};

function Engine::speedTo(v : integer) { //synatx sugar for function member with "this"
	this.speed = v; // use "this" instead of "self"
}

print(Engine.speed);
Engine->speedTo(12); //syntax sugar for method call with inplicity "this"
print(Engine.speed);

I took code and ideas from :

https://github.com/ex/Killa

https://github.com/sajonoso/jual

The default extension is ".ljs".

On folder lua2ljs there is a program to convert lua sources to ljs.

lua2ljs afile.lua > afile.ljs

This is based on Lua 5.3.5, released on 26 Jun 2018.

For installation instructions, license details, and further information about Lua, see doc/readme.html.

There is also the following port from lua to ljs:

ljsjit at https://github.com/mingodad/ljsjit

ljs-5.1 at https://github.com/mingodad/ljs-5.1

ZeroBraneStudio port at https://github.com/mingodad/ZeroBraneStudioLJS

raptorjit-ljs at https://github.com/mingodad/rpatorjit-ljs

snabb-ljs at https://github.com/mingodad/snabb-ljs

premake5-ljs at https://github.com/mingodad/premake-core/tree/ljs

CorsixTH-0.62-ljs at https://github.com/mingodad/CorsixTH-ljs

The tool lua2ljs does the convertion on almost all Lua code, except dynamic Lua code inside strings, C/C++ code, auxiliar scripts and makefiles, LJS also flag as warning/error duplicate variable declarations and a revision is needed mainly using "ljsc -p -l ljsSource.ljs > /dev/null" to only compile and emit the warnings/error to stderr, then several text scans to search and replace "nil", ".lua" and Lua code inside strings, ...

Finally run the tests if available to check that it's working properly (at least with the tests).

ljs's People

Contributors

mingodad avatar

Watchers

Arnstein Henriksen avatar James Cloos avatar  avatar

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.