lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I'm glad that FusionScript don't use \ for calling methods.
Charles Heywood <>于2016年12月4日 周日上午12:09写道:

I've been working on a programming language called FusionScript for the last
few months, and I've finally finished a basic compiler that can transform some
basic syntax from FusionScript to Lua. Please note that this compiler is HIGHLY
EXPERIMENTAL and bugs are almost guaranteed.

A Markdown version of this announcement is available:
== Downloading the Compiler and Runtime ==

The current runtime as of now is
commit 87231d2. It can be downloaded with Git or the GitHub interface. If you
use the GitHub interface, I cannot guarantee the version that is downloaded is
the one this guide is written for.

The software can be installed using LuaRocks: `luarocks make` optionally with
the `--local` flag for local installations. After installation, the `fusion`
and `fusionc` commands (as well as some more in-depth commands) are available.
Please use the README on the GitHub link for more information.

print("Hello World!");

== Syntax, basically ==

FusionScript is based off a C-like statement structure mixed with Python
generators and runs on the Lua VM. I picked the name FusionScript because I
feel the language is a great "fusion" of the three. As of right now, the syntax
is mostly solidified and is available at the link below:

= Values =

Numbers work exactly as they would in Lua; however, the usage of `0` for octal
numbers should not be relied on as the syntax may be changed in the future.
Strings are still in development and do not work exactly as the FusionScript
wiki says they should - as of right now, double-quoted strings work as they
would in Lua and single-quoted strings read any input but do not interpret
escape sequences. `\` acts as it's text representation. `true`, `false`, and
`nil` are the same as they would be in Lua.

Tables currently do not allow a trailing comma and do not allow semicolons as
field delimiters; however, they act exactly as they would in Lua otherwise.

= Statements =

Statements are almost entirely parallel to how they work in Lua, with some
changes that might seem more "familiar" to someone who's used C or C++.
Statements must end in a `;` and using a `{` and `}` denotes that multiple
statements are expected - a block (the list of statements between curly braces)
can be left empty and nothing will be evaluated, similar to `do` and `end` in

Function calls, assignments, `yield`, `break`, and `return` are all valid
statements; all but `yield` should be familiar to anyone using Lua. With the
stock Lua VM version of FusionScript, `yield` acts like `coroutine.yield`.
Assignments work almost exactly like they do in Lua with the exception of
"destructuring" assignment:

local {abs, floor} = math;

= Variables =

Variables use the same rules as they do in Lua with a very small exception -
using the `@` symbol in front of a variable acts like `self`.

= Comments =

Currently, comments are implemented as statements and must be terminated using
a semicolon. Besides that, comments can work exactly like they can in Lua,
starting with `--`. Comments do not automatically terminate at the end of the

= Expressions =

A small change with expressions between Lua and FusionScript is that the ~=
operator has been changed for the != operator, and `and` and `or` have been
replaced with && and ||. Expressions are implemented using a postfix format
surrounded with parenthesis. This makes parsing faster and reduces the chance
of errors when writing complex math expressions. Example:

print((* 5 (+ 2 3))); -- should print 25 ;

All literal values - strings, tables, `nil`, `true`, and `false` - act as an
_expression_ and do not need to be surrounded by parenthesis.

= Conditional Blocks =

`if` statements work the same as they would with Lua, with `elseif` and `else`
keywords adding more conditions to the section. This is different to how the
language worked before commit 08fdddc, which was changed to allow for easier
compiling and creating less change between Lua and FusionScript.

if true
	print("Hello World!");
elseif (&& true false)
	print("Goodbye World! Your logic is dead!");

Curly brackets are not used in the above example because there is only one
statement between the blocks. This works like it would in C and _javascript_.

= Loops =

The most basic loop in FusionScript is the `while` loop. The loop works almost
exactly like it would in Lua:

x = true;
while (== x true) {
	x = false;

The next loop is the numeric `for` loop. This loop also works like it does in
Lua, with a required start and stop and an optional step.

for (i=1, 10, 2) {
	print(i); -- Print odd numbers from 1 to 10 ;

The last loop - at least, when used as a statement - is the iterative `for`
loop. This one acts like the `for`/`in` loop in Lua:

local t = {6, 7, 8, 9, 10};
for _, v in ipairs(t)

There is also a way to use a loop within a function call, called a `generator`:

print(line in io.lines("file.txt"));

This syntax can also be extended to discard unwanted variables or to transform
an _expression_.

print(tostring(v) for k, v in pairs(_G));

The syntax also works with table generation!

local a = {1, 2, 3, 4, 5};
local b = {
	value ^ 2 for _, value in pairs(a)

Functions are implemented as a variation of MoonScript functions. However, they
work almost entirely the same as they do in Lua. A neat quirk about functions
is that they can assign to almost *any* value. Unlike Lua, where you have to
assign an anonymous function when using a variable index (`t[5]`, for example),
FusionScript allows you to just type that in the name and the parser handles
assignment automagically.

function_name(arg1, arg2)->
	print(arg1, arg2);

Like MoonScript, FusionScript also has default values for any arguments:

print_thing(line = "thing")->

Functions can also be treated as "lambdas" that only return an _expression_. This
syntax should mostly be used for anonymous lambdas (see below) to help avoid

}, (first, second)-> (<tostring(first) tostring(second)));

Functions that use the `self` operator can optionally use `=>` instead of `->`
(like in MoonScript) and the operator will automatically be added to the
argument list.

= Asynchronous Functions =

Function definitions that are preceded by the word `async` will be created into
a wrapper function that returns a wrapped coroutine. This can be useful for
writing Pythonic iterators:

async get_input()->
	while true

print(line in get_input()); -- echo lines from stdin ;

=== Note ===

Class generation did not make it into the initial testing release of