lua-users home
lua-l archive

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

Trying to find in C program the length of a table with lua_objlen that returned zero, though there are entries in the table (I made them myself). Testing in the lua interpreter gives the following results I cannot explain:

Lua 5.1.3  Copyright (C) 1994-2008, PUC-Rio
> local io = require "io" print(io, #io)
table: 0x102080	0
> local ta= {"a","b","c"} print(ta, #ta)
table: 0x107af0	3

Both are tables, the former gets length 0, the latter length 3.
Surely there are entries in the first because the following program shows it:

Lua 5.1.3  Copyright (C) 1994-2008, PUC-Rio
> function showtb(s, t)
>> print (s, " size = "..#t, ":", t)
>> if t then for k,v in pairs(t) do print(k,v) end end
>> end
> local io = require "io" showtb("io is:",io)
io is:	 size = 0	:	table: 0x102080
lines	function: 0x101f20
write	function: 0x1023a0
close	function: 0x1020a0
flush	function: 0x101ec0
open	function: 0x102260
output	function: 0x1022a0
type	function: 0x102380
read	function: 0x102320
stderr	file (0xa0216424)
stdin	file (0xa0216374)
input	function: 0x101ee0
stdout	file (0xa02163cc)
popen	function: 0x1022e0
tmpfile	function: 0x102340
> ^D

I searched the book and the reference manual and possibly overlooked the solution. But what happens here?

Hans van der Meer