Re: Turning Lua into C++ (was: alleviate the load of the GC)

  • From: Aleksandar Kordic <alexandarkordic@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 2 Sep 2015 17:20:53 +0200



I'd add only one thing -- differentiating between initialization and
assignment. Which means that "a = 2" should error if a can't be found in
scope rather than creating a new global variable; I'd suggest "global a =
2" for that.


You can use this before your code ;)

local __global_mt = {}
setmetatable(_G, __global_mt)
__global_mt.__newindex = function (t, name, value)
assert(false, string.format("Script attempted to create global variable
%q stack:%s", name, debug.traceback("", 1)))
end
__global_mt.__index = function (t, name)
assert(false, string.format("Script attempted to access unexisting
global variable %q", name))
end

Other related posts: