Shop OBEX P1 Docs P2 Docs Learn Events
lookup/lookupz — Parallax Forums

lookup/lookupz

i need to use lookupz to find an indexed value in a list. Can I put the list in a DAT statment in the top Obj? If so, how?
Jim

Comments

  • AribaAriba Posts: 2,685

    @RS_Jim said:
    i need to use lookupz to find an indexed value in a list. Can I put the list in a DAT statment in the top Obj? If so, how?
    Jim

    If you have the list in a DAT section, you don't use LOOKUP(Z), you just access the list as an indexed array element:

    PUB ...
      val := table[index]
    
    DAT
    table  byte  "ABC",55,99,0
    
    

    This works also with WORD and LONG lists.

    Andy

  • @Ariba Andy, I set up my DAT table in my top object and then tried to access it from my child object, no luck, it wont compile, saying that my table is not an array.. If I move the table to the child obj, then it compiles fine. I must be missing something, any suggestions? the whole idea was to get the data in the top object to make the child more universal in its usage.
    Jim

  • JonnyMacJonnyMac Posts: 9,003
    edited 2021-11-30 16:19

    Jim,

    You are going to need to pass a pointer to the parent array to the child object. You could put a method in the child called set_table().

    pub set_table(pntr)
    
      p_table := pntr
    

    ...where p_table is a global long in the child. Call this from the parent:

      child.set_table(@table)
    

    Now you can do this in the child:

    pub get_table_element(idx) : value
    
      value := byte[p_table][idx]
    
  • AribaAriba Posts: 2,685

    You need to pass the address of the table to the child object. And there access the table with byte[], word[], or long[]
    Something like that:

    PUB main
      child.init(@mytable)
    
    DAT
    mytable  byte  "ABC",55,99,0
    
    
    child Object:
    
    VAR
     long table
    
    PUB init(tbl_ptr)
      table := tbl_ptr
    
    PUB ...
      val := byte[table][index]
    
Sign In or Register to comment.