the ambiguity in 5.0 reference manual

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

the ambiguity in 5.0 reference manual

google-8
If I have a statement like:

        somedata.foo(arg1,arg2)

now,what is the type of somedata? a table or a userdata?

according to the reference manual in

2.3 - Variables

"The syntax var.NAME is >>just<< syntactic sugar for var["NAME"]:

        var ::= prefixexp '.' Name"

"Square brackets are used to index a table:

        var ::= prefixexp '[' exp ']'

The first expression (prefixexp)  >>should<<  result in a >>table<< value;"

Now,according to the reference manual,the somedata is a table.
But really it is a userdata. Is there something Wrong?




Reply | Threaded
Open this post in threaded view
|

Re: the ambiguity in 5.0 reference manual

Edwin Eyan Moragas-2
On 5/30/06, google <[hidden email]> wrote:

> If I have a statement like:
>
>         somedata.foo(arg1,arg2)
>
> now,what is the type of somedata? a table or a userdata?
>
> according to the reference manual in
>
> 2.3 - Variables
>
> "The syntax var.NAME is >>just<< syntactic sugar for var["NAME"]:
>
>         var ::= prefixexp '.' Name"
>
> "Square brackets are used to index a table:
>
>         var ::= prefixexp '[' exp ']'
>
> The first expression (prefixexp)  >>should<<  result in a >>table<< value;"
>
> Now,according to the reference manual,the somedata is a table.
> But really it is a userdata. Is there something Wrong?
>

might be a metatable to an userdata. kindly check the section on
metatables

http://www.lua.org/manual/5.0/manual.html#2.8

--
salud,
eyan

http://www.eyan.org
Reply | Threaded
Open this post in threaded view
|

Re: the ambiguity in 5.0 reference manual

Petite Abeille
In reply to this post by google-8

On May 30, 2006, at 08:09, google wrote:

> Now,according to the reference manual,the somedata is a table.
> But really it is a userdata. Is there something Wrong?

It's a bit more exotic then that as any object can have a metatable
associated with it:

local aString = "abcd"
local aFunction = aString[ "upper" ]

print( aFunction( aString ) )
-- or print( aString.upper( aString ) )
-- or print( aString:upper() )

 > ABCD

local aNil = nil

debug.setmetatable( aNil, { __index = { toString = function( aValue )
return tostring( aValue ):upper() end }  } )

print( aNil:toString() )

 > NIL

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/