Project

General

Profile

Bug #12662 ยป ruby-bug.c

I am on a Debian stretch/sid and compile the example program with gcc -g `pkg-config --cflags ruby` ruby-bug.c `pkg-config --libs ruby` -o ruby-bug - rocco (Rocco Carbone), 08/09/2016 08:51 AM

 
/* System headers */
#include <stdio.h>

/* The implementation */
#include <ruby.h>


static void hash_test (void)
{
VALUE ht;
unsigned key;
VALUE hit;

/* Construct the VM */
ruby_setup ();

/* Create and initialize a new hash table */
ht = rb_hash_new ();

key = 1999;
printf ("Get [key %u] ... ", key);
hit = rb_hash_fetch (ht, INT2NUM (key));
if (hit)
printf ("%d\n", NUM2INT (hit));

/* Free all resources allocated by the hash */
rb_hash_clear (ht);

/* destruct the VM */
ruby_finalize ();
}


int main (int argc, char * argv [])
{
printf ("Integer keys and Integer values\n");
hash_test ();

return 0;
}
    (1-1/1)