lua-users home
lua-l archive

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




On 2018-03-14 11:11 AM, Roberto Ierusalimschy wrote:
I mean: if I can pass something to a function, and I can get it back from a
call... well it is a value!
That is true. But you cannot pass 'undef' to a function or return
an 'undef' from a function (anymore than you can pass 'while' to a
function).

-- Roberto


Shouldn't undef just expose the C LUA_TNONE to Lua + some neatness?

With the restrictions that it can only be used as arguments, table values, or to undefine locals (non-lexical or semi-lexical variable scoping).

string.sub("hello", undef, 3) -- would return "hel"

t[i] = undef -- would erase t[i]

-- non-lexical variable scoping
x = 1
local x = 2
do
  x = undef
  assert(x == 1)
  local x, x, x = 3, 4, 5
  assert(x == 5)
  x = undef
  assert(x == 4)
  x = undef
  assert(x == 3)
  x = undef
  assert(x == 1)
end
assert(x == 2)
-- (this can also be made to work with upvalues obviously. at the end it just undefines the global.)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.