erde-lang / erde

A programming language that compiles to Lua.
https://erde-lang.github.io
MIT License
38 stars 4 forks source link

Lua keyword limitations #18

Closed bsuth closed 1 year ago

bsuth commented 1 year ago

Erde's current behavior for handling Lua keywords that are not keywords in Erde is as follows:

  1. If it is a standalone variable, transform it

Erde:

local end = 1

Lua:

local __ERDE_SUBSTITUTE_end__ = 1
  1. If it is a table value, escape it

Erde:

local t = { end = 1 }
print(t.end)

Lua:

local t = { ["end"] = 1 }
print(t["end"])

However, this still has the following limitations:

  1. Mismatched names when accessing _G / _MODULE

Erde

global end = 5
print(end)
print(_G.end)

Lua

global __ERDE_SUBSTITUTE_end__ = 5
print(__ERDE_SUBSTITUTE_end__)
print(_G.end) -- nil
  1. In rare cases, an IIFE must be used in compiled code (see this issue). In this case, the function call may appear in error stacktraces.

Erde

print(a.b:end())

Lua

print((function()
  -- Error may occur in this function, for example if `a` is nil
  local tmp = a.b
  return tmp["end"](tmp)
end)())
bsuth commented 1 year ago

closed by https://github.com/erde-lang/erde/commit/10898e493c109494087b9eacdd4e61bb0775b943