On Mon, May 11, 2009 at 3:59 PM, klaas.holwerda <n...@klaasholwerda.nl>wrote:

> Hi,
>
> I want to wrap tuples like in python, but in lua its a table initialized
> for a function with{}.
> This makes it possible to mention only the parameters the user wants to
> specify, and not a whole range, which is hard to remember in position etc.
> But in my case certain groups of arguments are related, while others are
> for other task done with the same command. So  it would be very hard to
> use from Lua, or even C++, doing it the standard way with simple
> arguments to a function.
>
> It is explained here, how its done in lua:
>
> http://www.lua.org/pil/5.3.html
>
> In wxLua i like to use:
>
> wx.a2dCommand_GroupAB{ what = a2dCommand_GroupAB:BoolOperation_GroupAB,
> operation = BOOL_A_SUB_B, selectedA = true, selectedB = true }
> AddCommandToMenu( booleanObjects, _("Boolean A-B"), _("Boolean
> Subtract"), command );
>

wxLua does not save the string name of function parameters so they can't be
looked up later. I do use this facility in Python and like it, but I think
it might bloat the wxLua bindings even more.

Currently, each binding function is crafted to get and check the input
parameter type with the minimum of code. Allowing a table like this means
that we'd have to look through it and assign the variables as they come,
keep track of them all to give messages about missing required parameters,
while still allowing for positional arguments. It might also be a lot slower
since you have create the wxVariant, fill it, then read it out as opposed to
simply creating the correct variable type, filling it, and using it as is.

I have thought briefly about using a wxVariant type holder for each
parameter, but I can imagine that there might be some trouble leading to a
lot of hand crafted bindings. It's a *big* change for wxLua that's built
into the Python interpereter. On the other hand, the error messages could be
quite a bit more informative and this would allow for better interactive
help like Python.

BUT maybe it could wrap directly in to what is show down here, and that
> would be save and compiler checked.
> Like a special keyword in the *.i file, that has a function definition,
> with all possible arguments/tuples,  and  wraps them in a special way to
> C++.
> Like iterating over the table, and for each key in there, call a
> specific Args::argumentX() function.
> After the iteration the Args object containing all arguments found is
> complete, and the constructor is called with that Args objects as
> parameter.
>

wxLua does already save the variable types in an array. See
http://wxlua.cvs.sourceforge.net/viewvc/wxlua/wxLua/modules/wxbind/src/wxcore_bind.cpp?revision=1.21&view=markup
Search for : s_wxluatypeArray_wxLua_function_wxDirSelector

We could simply add another const char** array of the string names for each
variable to go with the types and yes we could then create an array of
wxVariants (or more likely our own variant class based on the wxluatype_XXX
integers for types).

In fact, we may be able to get away with a simple non-typesafe wxVariant
type class like this.

class wxLuaVariant
{

long GetLong(); // for char, short, int, long
double GetDouble();
void* GetPointer(); // you cast this to whatever class, Lua table, you want
int GetwxLuaType(); // for someone else to check.

union m_value { long, double, etc, and of course void* for classes };
int m_wxltype;

}


> Currently inside C++ i do something like the above, but used from within
> C++ itself.
> That is based on the Args object, its members functions returning a
> reference to itself:
>
> a2dCommand_GroupAB* command = new a2dCommand_GroupAB(
> a2dCommand_GroupAB::Args().
>                what( a2dCommand_GroupAB::BoolOperation_GroupAB ).
>                operation( BOOL_A_SUB_B ).
>                selectedA( true ).
>                selectedB( true ) );
> AddCommandToMenu( booleanObjects, _("Boolean A-B"), _("Boolean
> Subtract"), command );
>

That is... different. I'm not sure it seems natural to me, but it is a
little more verbose.

I am currently working on adding the ability to have multiple base classes.
It's not too hard, but I have to ensure that I change all the code that
expects a single base class to not recurse into the list of base classes.

Regards,
    John
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to