Iterating through Lua userdata (Scite props)?

2,446 views
Skip to first unread message

sdaau

unread,
Mar 21, 2011, 3:09:35 PM3/21/11
to scite-interest
Hi all,

I would like to iterate through, and print out methods and properties
of 'editor' object, and the content of 'props' (a pseudo-array, as
http://lua-users.org/wiki/UsingLuaWithScite calls it) from Lua. I am
trying the following function:

function PrintProps()
print(editor)
print(props)
print(tostring(editor))
print(tostring(props))
print(getmetatable(editor))
print(getmetatable(props))

-- iterate over array:

-- bad argument #1 to 'pairs' (table expected, got userdata):
--~ for i,v in pairs(editor) do print(i,v) end
--~ for i,v in pairs(props) do print(i,v) end

-- ipairs don't work below?
print("---1---")
for i,v in pairs(getmetatable(editor)) do print(i,v) end
print("---2---")
for i,v in pairs(getmetatable(props)) do print(i,v) end
end

.... and I'm getting the following output:

userdata: 0x8469de4
userdata: 0x860c1cc
userdata: 0x8469de4
userdata: 0x860c1cc
table: 0x85cecf0
table: 0x85cebf0
---1---
__newindex function: 0x85bd8c0
textrange function: 0x85ceeb8
findtext function: 0x85bd8d8
insert function: 0x85ceef0
append function: 0x85cee58
remove function: 0x85cee40
__index function: 0x85bd888
match function: 0x85ceff0
---2---
__index function: 0x85cec18
__newindex function: 0x85cec50

So, some functions do get shown for 'editor', but I cannot get to,
say, props['FileName'] and such... Is that possible to do at all - and
if so, would anyone have a reference to a snippet?

Thanks in advance for any responses,
Cheers!

sdaau

unread,
Mar 21, 2011, 3:24:10 PM3/21/11
to scite-interest
Hi again,

> I would like to iterate through, and print out methods and properties
> of 'editor' object, and the content of 'props' (a pseudo-array, ashttp://lua-users.org/wiki/UsingLuaWithScitecalls it) from Lua. I am
> trying the following function:
>

Ups.. just found this:
Iterate over userdata members - http://forum.luahub.com/index.php?topic=1702.0

> As long as these key/value information are not
> stored inside a general purpose table-like data
> structure within your C classes, it will be very
> painful to allow such iteration since you would need
> to do "manual" iteration.
>
> So it depends how your __index metamethod of your
> userdata is implemented. Example (Lua code, but
> applies to C as well):

Phuuh.. this doesn't look good for obtaining a list of 'props', does
it? Or is there an easier way?

Thanks again,
Cheers!



On Mar 21, 8:09 pm, sdaau <s...@imi.aau.dk> wrote:
> Hi all,
>
> I would like to iterate through, and print out methods and properties
> of 'editor' object, and the content of 'props' (a pseudo-array, ashttp://lua-users.org/wiki/UsingLuaWithScitecalls it) from Lua. I am

Neil Hodgson

unread,
Mar 21, 2011, 10:13:43 PM3/21/11
to scite-i...@googlegroups.com
SciTE's properties are structured in levels and are not a simple
list. They are presented like an array to make it easy to read the
value of a property. There is no support for iterating props.

Neil

sdaau

unread,
Mar 22, 2011, 2:04:00 AM3/22/11
to scite-interest
Hi Neil,

Thanks for the prompt answer!

> SciTE's properties are structured in levels and are not a simple
> list. They are presented like an array to make it easy to read the
> value of a property. There is no support for iterating props.
>

I see - thanks for that, good to have this in writing ! :)

All the best,
Cheers!
Reply all
Reply to author
Forward
0 new messages