Thursday, April 06, 2006

more than one instances of a module in via swig

Put all global vars in a structure
typedef struct mod_data{
...
}

have functions like
init(mod_data*, ...)
f1(mod_data*)
finalize(mod_data*)

in interface file say

%pointer_functions(mod_data, mod_data_p)

in python wrapper have a class for the module
import swig_module as sm
class module:
def __init__(self):
self.my_mod_data_p = sm.new_mod_data_p() #this guy will malloc for the mod_data structure and returns the pointer to the structure.
sm.init(self.my_mod_data_p)
#now you can use this self.my_mod_data_p every where in the module.
#if someone will create new instanced you will have different structure for that guy.

BUT what if i couldn't put all the things in a single structure???

Wednesday, April 05, 2006

sed: don't tell me if I didn't ask

By default sed 's' print everything it doesn't match.
If you want only matching things, use p with -n option
sed -n 's///p'