A
Andreas Lundgren
Hi!
I'm building an API for a HW, and this API has a lot of wrapper
functions that wraps Win32OLE-calls. All these wrapper functions are
quite alike. In stead of writing a lot of duplicated Win32OLE-code, I
would like to generate these functions using Marcos.
Basically I want to define one macro that expands to several
functions.
_____Simple Example_____
Template: define ADDX(Xname, Xval) <- Here i need help, how to write
this kind of macro?!?
The intension is that when I put this in my script
ADDX("Two",2)
ADDX("Four",4)
It should be expanded and make these two functions available:
sub AddTwo
{
$ret = _@[0] + 2
}
sub AddFour
{
$ret = _@[0] + 4
}
_____In the real case_____
Macro definitions should be something like this:
SET_VALUE(f_name, method, no_of_params)
Later I will include the macro with for example this parameters:
SET_VALUE("InitDriver", "ext_driver_init", 4)
And it should expand to something like this:
sub InitDriver # Here the "InitDriver" is from Marco Expansion
{
( 4 == scalar( @_ ) ) or die( "Incorrect Number Of Arguments.\n" );
# Here the "4" is from Marco Expansion
ole_arg_list = join(';',@_);
my $ewaApp = Win32::OLE->new('ewa.Application');
# Some code for the Win32OLE
$ewaApp.call(['MethodNameIn','Params'],
['ext_driver_init',ole_arg_list]);
# Here the "ext_driver_init" is from Marco Expansion
}
Is it possible to write macros that create functions like this?
BR,
Andreas - Sweden
I'm building an API for a HW, and this API has a lot of wrapper
functions that wraps Win32OLE-calls. All these wrapper functions are
quite alike. In stead of writing a lot of duplicated Win32OLE-code, I
would like to generate these functions using Marcos.
Basically I want to define one macro that expands to several
functions.
_____Simple Example_____
Template: define ADDX(Xname, Xval) <- Here i need help, how to write
this kind of macro?!?
The intension is that when I put this in my script
ADDX("Two",2)
ADDX("Four",4)
It should be expanded and make these two functions available:
sub AddTwo
{
$ret = _@[0] + 2
}
sub AddFour
{
$ret = _@[0] + 4
}
_____In the real case_____
Macro definitions should be something like this:
SET_VALUE(f_name, method, no_of_params)
Later I will include the macro with for example this parameters:
SET_VALUE("InitDriver", "ext_driver_init", 4)
And it should expand to something like this:
sub InitDriver # Here the "InitDriver" is from Marco Expansion
{
( 4 == scalar( @_ ) ) or die( "Incorrect Number Of Arguments.\n" );
# Here the "4" is from Marco Expansion
ole_arg_list = join(';',@_);
my $ewaApp = Win32::OLE->new('ewa.Application');
# Some code for the Win32OLE
$ewaApp.call(['MethodNameIn','Params'],
['ext_driver_init',ole_arg_list]);
# Here the "ext_driver_init" is from Marco Expansion
}
Is it possible to write macros that create functions like this?
BR,
Andreas - Sweden