lua-users home
lua-l archive

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


Op Do. 7 Mrt. 2019 om 09:36 het Magicks M <m4gicks@gmail.com> geskryf:
>
> I'm not sure an intangible second class value to represent a concept is the lua way either.

The phrase "intangible second class value" deserves a compliment. It
misleads the reader by taking for granterd that 'none' is a concept,
represented by some kind of value.  Actually T_NONE is just a name for
an integer constant in C. There is no concept 'none', let alone a
value of whatever class to rpresent it. It might as well have been
called "missing" or "absent".

Read the manual carefully. Carefully. Every bit of it. In particular, this part:

~~~~
lua_type

[-0, +0, –]

int lua_type (lua_State *L, int index);

Returns the type of the value in the given valid index, or LUA_TNONE
for a non-valid (but acceptable) index. The types returned by lua_type
are coded by the following constants defined in lua.h: LUA_TNIL (0),
LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION,
LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA.
~~~~

> The only reason it exists is due to the way the C API retreives arguments from the stack.

This statement is so vague that it is not even wrong.

T_NONE exists because Lua calls are allowed to provide any number of
arguments, and it is not a priori an error to provide fewer values
tnan the function woukl have been able to use.

It is not good enough just to say that missing arguments are nil. For
example, the library function table.insert, since
table.insert(tbl,key,nil) and table.insert(tbl,item) do different
things. You really need to know whether that third argument is
actually present.