function or userdata

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

function or userdata

Hugo <Nabble>
value = function() end
print(type(value))
This code prints "userdata", not "function". Is this correct?

http://www.lua.org/manual/5.2/manual.html#2.1

The type userdata is provided to allow arbitrary C data to be stored in Lua variables. A userdata value is a pointer to a block of raw memory. There are two kinds of userdata: full userdata, where the block of memory is managed by Lua, and light userdata, where the block of memory is managed by the host. Userdata has no predefined operations in Lua, except assignment and identity test. By using metatables, the programmer can define operations for full userdata values (see ยง2.4). Userdata values cannot be created or modified in Lua, only through the C API. This guarantees the integrity of data owned by the host program.
Reply | Threaded
Open this post in threaded view
|

Re: function or userdata

Hugo <Nabble>
Luan also prints "userdata" for tables. I tested the code below:
t = {
  function() end
}
print(type(t[1]))
print(type(t))
When I run it with standard Lua, I get:
function
table
When I run it with Luan I get:
userdata
userdata
Reply | Threaded
Open this post in threaded view
|

Re: function or userdata

fschmidt
Administrator
fixed in rev 86
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: function or userdata

Hugo <Nabble>
It works now, thanks.

Closing thread.