Thursday, September 20, 2007

tips on ruby embeding

Ruby has more clean and comprehensive object-oriented framework than Python. I started to learn Ruby and embed it with some C program. It is turned out that Ruby is still in its early stage and has lots of stuff to be cleaned. One issue I met is the shebang handling.

In Ruby, when it read the input file, it will check whether the shebang (the 1st if it is started with '#!') refers to itself. Otherwise, it will invoke the shebang to invoke the corresponding executables. But, by "itself", it only refers to "ruby". It will cause errors when your Rub-embedded interpreter cannot be recoganized as "itself." Hence, it is recursively being called and finally fails due to lack of resources.

A simple work-around is to put "ruby" into your Ruby-embedded interpreter name to fake as a Ruby interpreter "itself."

More systemetric solution is to check shebang with argv[0] instead.