How do I create a dynamic wrapper for another language?

  • Thread starter Whitney Battestilli
  • Start date
W

Whitney Battestilli

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)

iD8DBQBArX3bDc8M60vtLoURAgLjAJwLVOvQumPFlMTorRepaO43AGUBqQCeMLOx
tM8ADgxlY4PPl14uO4gtNuA=
=It2R
-----END PGP SIGNATURE-----
 
D

Donald 'Paddy' McCarthy

Whitney said:
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/~pinhong/scriptEDA/dst.html

Pad.
 
H

has

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.sanderson/appscript.html
 
W

Whitney Battestilli

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.

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.sanderson/appscript.html


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

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

iD8DBQBAri6kDc8M60vtLoURAviDAJ42SXwnOigzSsQL01tmqXhTuG0TCgCeMGMm
KrWminUurzVC7Ui4FVAyYVY=
=Fuj/
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top