[Tutor] How to wrap ctype functions
knacktus at googlemail.com
Wed Mar 3 18:43:28 CET 2010
I wonder what's the best way to wrap given function calls (in this case
ctype function calls but more generally built-in functions and those kinds).
I have a huge c library and almost all functions return an error code. The
library also contains a function, that returns the corresponding error
message to the error code. So, what I need to do for every call to one of
the libraries functions looks like this:
error_code = my_c_library.SOME_FUNCTION_
if error_code != 0:
error_message = my_c_library.GET_ERROR_TEXT(error_code)
print "error in function call SOME_FUNCTION_CALL"
Also, for some function calls I would need to do some preperations like:
error_code = my_c_library.LOG_IN_AS_ADMINISTRATOR(admin_user,
error_code = my_c_library.SOME_FUNCTION_CALL(argument)
I like the decorator idea, but I can't figure out if it's applicable here.
To be able to call the function in a manner like this would be great, e.g.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor