Skip to content

seanpringle/lt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LT - Lua Tweaked

A rainy day week experiment to see what Lua syntax would be like with:

  • Local variables by default
  • An array type
  • 0-based indexing
  • Integer 0 is false
  • Tables can store nil
  • New tables' metatable defaults to table
  • Assignment is an expression (returns value)
  • Ternary operator (inline-if expression)
  • Pattern syntax is PCRE
  • String interpolation
  • Stricter prototype-style inheritance
  • Userdata are all light pointers
  • Reference counting
  • Concurrent cycle detection (heh!)
  • Avoid use of longjmp

Don't think of LT as anything but an experiment. Bugs abound, and there's a heap of stuff not done (yet, or maybe ever...):

  • No iterators
  • No metamethods
  • Standard libraries have big gaps or are missing entirely
  • Only numeric for exists, and is limited to a simple 1+ counter
  • Not (easily) embeddable

Local variables by default

function hello ()
  text = "hello world"
  print(text)
end

hello()
print(text) -- error

Global variables are writable via a global table:

function hello ()
  global.text = "hello world"
  print(text)
end

hello()
print(text) -- success

An array type

Dynamic arrays (tuple, vector, etc) passed by reference.

stuff = [1,2,3]

for i in #stuff do
  print(stuff[i])
end

stuff[#stuff] = 4

The [] notation plays funny with Lua [[...]] strings. To nest array literals, add spaces.

0-based indexing

Lua's 1-based indexing only seemed a bother when interacting with other stuff in the C-derived ecosystem, but there's a lot of that around. This affects the array type and strings.

Integer 0 is false

Lua treats only nil and false as false. LT adds 0 to the mix.

Tables can store nil

stuff = { a = 1, b = nil }
print(stuff)
{a: 1, b: nil}

Obviously this means LT can't delete table items by setting them to nil, as Lua does. Still thinking about this...

Assignment as expression

while line = io.read() do
  print(line)
end

Ternary operator (inline-if)

print(if true then "yes" else "no" end)

Stricter prototype-style inheritance

Stricter because it currently omits a bunch of cool stuff one can do with Lua's metatables and metamethods. Below, inherit is the equivalent of calling setmetatable and setting __index.

a = {
  alpha = function ()
    print("alpha!")
  end
}

b = inherit(a, {
  beta = function ()
    print("beta!")
  end
})

b.alpha()

Releases

No releases published

Packages

No packages published