This documents the features and adjustments that I would personally like to see integrated with Lua, although this amount of tweaking and additions could likely make a project implementing them to be considered an entirely different language. The affect on performance and feasibility of these suggested features should be carefully considered previous to beginning the implementation of any.
- Class Syntax (inheritance, constructors, destructors, string representation, private methods and variables)
- Operator Overloading (integrated with classes)
- Improved Scope Syntax (new local and global variable types)
Constant variables- Promises (asynchronous functions)
Switch Conditional Syntax (automatically break unlesscontinue
)- Variable = Variable + This syntax (+=, -=, *=, etc...)
- A likeness of the ternary operator
- Simple Pointers
- Use slashes for comments
- Change starting array index to
0
Use+
instead of..
to concatenate strings (consistency, cleaner, makes sense when considered similar to operator overloading)str()
instead oftostring()
andint/num()
instead oftonumber()
- Change tables to be pass-by-value rather than pass-by-reference (a table passed to a function which modifies it currently affects the original variable containing the table, unless a copy of the table is first created using
table.copy
)
Note: Suggested implementations for several of the crossed out features listed above can still be found below. Not only that, but any line of code that is completely commented without explanation is equal to that of "crossed out" items above.
class example
construct(var)
self.variable = var -- public member variable
self._private = "hello" -- private member variable
end
destruct() -- optional
self = nil -- example
end
function aMethod(var)
self._private = var
end
function _privateFunc(var) -- example private function
self._private = var
end
string() -- defines what happens when the object variable is printed by itself (e.g. print(newInstance))
return self.variable .. ": " .. self._private
end
end
class two extends example -- inherits public and private data from `example`
construct(var, another) -- overriding the constructor
self.variable = var
self._private = another
end
end
local newInstance = two("hello", "world")
class example
construct(x, y, z)
self.x = x
self.y = y
self.z = z
end
+(otherExample)
return example(self.x + otherExample.x, self.y + otherExample.y, self.z + otherExample.z)
end
end
local first = example(1, -1, 4)
local second = example(2, 3, 1)
local third = first + second -- x: 3, y: 2, z: 5
local lVar = 1 -- defines a local variable
global gVar = 1 -- defines a global variable
lVar = 2 -- changes an existing variable
nVar = 0 -- errors, this syntax cannot create a new variable but only modify an existing variable
function hello()
return Promise(function(resolve)
resolve(true) -- Return true
end)
end
hello().then(function(value)
print("Received: " .. tostring(value))
end)
switch num
if 0 then
print("0")
continue -- continue to next check
end
if < 10 then
print("less than 10") -- automatically break
end
if < 5 then
print("less than 5")
end
end
local bool = false
local var = if bool == false then "it is false" else "it is true" end
var = if var == "it is true" then true elseif var == "it is false" then false end
local variable = "Hello!"
print(variable) -- Prints "Hello!"
local pointer = *variable
pointer = "Changed by pointer."
print(variable) -- Prints "Changed by pointer."