Todd Lyons <tlyons@ivenue.com> writes:
Hi all, I'm embedding python into a c app (exim, the MTA). I've gotten code in to initialize python, read in the embedded script, call various functions within that script, and appropriately return data from those functions back to the exim call.
One thing that does not make sense yet though, is how to assemble the data to be passed to the python functions. Imagine the following simple function:
def simple_math(a,b): return a+b
In this case, a and b are integers or long integers. How can I format that incoming data without knowing in advance that there are two arguments to this function and that are both are integers?
Obviously the scripts and your embedding module need to agree on an API; for example, the script could look like this:
import exim
exim.modify_configuration(...) x = exim.query_something(...) exim.add_callback(my_function) ...
The "exim" module is provided by you as the embedder and serves for the script to access exim's functionality. (Otherwise the script would be executed as just another Python script, which would not be too useful from the embedding standpoint.)
In other words, you're not calling the functions from the script: the script is calling your functions. The only time that you are calling a script's function is when the script passes a function to one of your functions that accepts a callback argument -- but even then the interface of the function is regulated by you, and it is you who prescribe how many and what kind of arguments it will accept.
If the reason for this question is not clear, imagine that the sysadmin goes and edits the python script so that it now is:
def simple_math(name,a,b): // do something to log "name" to a logfile return a+b
What would be the point of such a function, before or after the edit? You cannot just call any random function from a script: you need to execute the script, providing a way for the script to call *you*.