Forum: Ruby How to use st_table by oneself?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
gpy g. (Guest)
on 2008-10-05 08:05
http://www.ruby-doc.org/doxygen/1.8.4/st_8c.html
Is there some tutorials or examples about it?thanks
Joel VanderWerf (Guest)
on 2008-10-05 23:33
(Received via mailing list)
gz zz wrote:
> http://www.ruby-doc.org/doxygen/1.8.4/st_8c.html
> Is there some tutorials or examples about it?thanks

hash.c in the ruby source might help.  Also, the Ruby Hacking Guide has
some info:

http://rhg.rubyforge.org/chapter03.html
gpy g. (Guest)
on 2008-10-06 05:25
Joel VanderWerf wrote:
> gz zz wrote:
>> http://www.ruby-doc.org/doxygen/1.8.4/st_8c.html
>> Is there some tutorials or examples about it?thanks
>
> hash.c in the ruby source might help.  Also, the Ruby Hacking Guide has
> some info:
>
> http://rhg.rubyforge.org/chapter03.html
oh,thank you!
My "hello world" with st_table:

#include <stdio.h>
#include <stdlib.h>
#include "st.c"
int main(int argc, char *argv[])
{
  st_table *tbl=st_init_numtable();

  st_insert(tbl,1,100);
  char *hello = "hello world";
  st_insert(tbl,2,(st_data_t)hello);
  st_data_t ret;
  if(st_lookup(tbl,1,&ret)){
                printf("%d\n",ret);
                                       }

  if(st_lookup(tbl,2,&ret)){
                printf("%s\n",ret);
                                       }

  st_free_table(tbl);
  system("PAUSE");
  return 0;
}
This topic is locked and can not be replied to.