469,923 Members | 1,745 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

How do I create a dynamic wrapper for another language?

I'm trying to embed python into an application that already contains a
scripting language. This scripting language contains thousands of
commands and I have the ability to query the script engine and get
syntax information regarding valid arguments and such.

Rather than writing explicate wrappers for each command (which will be
very time consuming), I would like to extend python by creating a module
that allows any function name to be executed with any number of keyword
arguments. I would then like to take the function name and keyword
arguments and pass these to the apps script engine in the format
required.

Is there any way to do this or any way to do something like this?

Thanks in advance for any suggestions that may be offered.

--Whitney.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQBArX3bDc8M60vtLoURAgLjAJwLVOvQumPFlMTorRepaO 43AGUBqQCeMLOx
tM8ADgxlY4PPl14uO4gtNuA=
=It2R
-----END PGP SIGNATURE-----

Jul 18 '05 #1
3 1882
Whitney Battestilli wrote:
I'm trying to embed python into an application that already contains a
scripting language. This scripting language contains thousands of
commands and I have the ability to query the script engine and get
syntax information regarding valid arguments and such.

Rather than writing explicate wrappers for each command (which will be
very time consuming), I would like to extend python by creating a module
that allows any function name to be executed with any number of keyword
arguments.. I would then like to take the function name and keyword
arguments and pass these to the apps script engine in the format required.

Is there any way to do this or any way to do something like this?

Thanks in advance for any suggestions that may be offered.

--Whitney.

Maybe this will point you in the right direction:
http://www-cad.eecs.berkeley.edu/~pi...ptEDA/dst.html

Pad.
Jul 18 '05 #2
has
> Whitney Battestilli wrote:
I'm trying to embed python into an application that already contains a
scripting language. This scripting language contains thousands of
commands and I have the ability to query the script engine and get
syntax information regarding valid arguments and such.

Rather than writing explicate wrappers for each command (which will be
very time consuming), I would like to extend python by creating a module
that allows any function name to be executed with any number of keyword
arguments.. I would then like to take the function name and keyword
arguments and pass these to the apps script engine in the format required.

Is there any way to do this or any way to do something like this?


It's pretty easy using Python's introspection features to supply the
syntactic sugar. Simple example:

class _Callable:
def __init__(self, name):
self._name = name

def __call__(self, **args):
# [Do argument name checking, etc. here]
# [Dispatch command here]
print 'Sending command %r with arguments: %r' % (self._name,
args) # TEST

class Bridge:
def __getattr__(self, name):
# [Do command name checking here]
return _Callable(name)
bridge = Bridge()
bridge.foo(bar=1, baz=True) # -> Sending command 'foo' with arguments
{'baz': True, 'bar': 1}
Also see my Python-to-Apple Event Manager bridge for ideas and/or
code: http://freespace.virgin.net/hamish.s...appscript.html
Jul 18 '05 #3
Has,

Thanks! This is exactly what I was missing.

I appreciate everybody's suggestions and the loads of general good info
on this list. I'm going to be able to get back into python for a few
months ( after a few year break ). I'll try to lurk on the list and
pitch in.

Thanks again,
--Whitney.

On Fri, 2004-05-21 at 10:33, has wrote:
Whitney Battestilli wrote:
I'm trying to embed python into an application that already contains a
scripting language. This scripting language contains thousands of
commands and I have the ability to query the script engine and get
syntax information regarding valid arguments and such.

Rather than writing explicate wrappers for each command (which will be
very time consuming), I would like to extend python by creating a module
that allows any function name to be executed with any number of keyword
arguments.. I would then like to take the function name and keyword
arguments and pass these to the apps script engine in the format required.

Is there any way to do this or any way to do something like this?


It's pretty easy using Python's introspection features to supply the
syntactic sugar. Simple example:

class _Callable:
def __init__(self, name):
self._name = name

def __call__(self, **args):
# [Do argument name checking, etc. here]
# [Dispatch command here]
print 'Sending command %r with arguments: %r' % (self._name,
args) # TEST

class Bridge:
def __getattr__(self, name):
# [Do command name checking here]
return _Callable(name)


bridge = Bridge()
bridge.foo(bar=1, baz=True) # -> Sending command 'foo' with arguments
{'baz': True, 'bar': 1}


Also see my Python-to-Apple Event Manager bridge for ideas and/or
code: http://freespace.virgin.net/hamish.s...appscript.html



Whitney Battestilli
Cell: 919-949-0686
OpenPGP Public Key

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQBAri6kDc8M60vtLoURAviDAJ42SXwnOigzSsQL01tmqX hTuG0TCgCeMGMm
KrWminUurzVC7Ui4FVAyYVY=
=Fuj/
-----END PGP SIGNATURE-----

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Steve Richfield | last post: by
18 posts views Thread by squaretriangle | last post: by
5 posts views Thread by bearophileHUGS | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.