[wax] In lua script, how to access obj-c instance variable?

229 views
Skip to first unread message

code0tt

unread,
Sep 26, 2012, 11:31:26 AM9/26/12
to ipho...@googlegroups.com
I try to pass a NSArray* object to lua script, and I will do something loop, but I cannot get NSArray* object's count, all try to access count of NSArray returns nil.
Please help!

function parse(self,parser) 

    local body = parser:body()

    local table = body:findChildOfClass("list-table")

    

    if table == nil then return end

    local titleNodes = table:findChildrenOfClass("subject")

    

    if titleNodes == nil then return end

    

    puts(titleNodes.count); -- it's will output nil

        

    for i=0, titleNodes.count -1 do -- app will crushed, access nil object

      local title = titleNodes:objectAtIndex(i)

      local spanNode = title:findChildOfClass("f14px")

      local anchorNode = spanNode:findChildTag("a")

    end

end


* and parameter "parser" is a HTMLParser instance.

Corey Johnson

unread,
Oct 8, 2012, 11:37:15 AM10/8/12
to ipho...@googlegroups.com
In Wax you can't call use dot-syntax to get properties for Objective-C objects. If you want to get something from an Objective-C object you need to use a method like titleNodes:count()

André Braga

unread,
Oct 8, 2012, 3:01:12 PM10/8/12
to ipho...@googlegroups.com
Moreover, -count has never been a property. Using dot syntax to access it as a property is abusing the compiler and /could/ become a problem in the future. I strongly suggest to always check the documentation instead of happily dotting around...
Reply all
Reply to author
Forward
0 new messages