I'm trying to bind a function to Lua which has optional parameters in BlitzMax. Ideally, I would prefer to set those default values in BlitzMax, and not in the lua-side bindings. Now I know I can use lua_gettop to count the parameters on the stack. That part is ok. What I'm having a problem with is binding it correctly on the Lua side.
Now Lua features dynamic (and somewhat weak) typing, so I cannot overload the functions the way I could in C, so I can only have one function prototype regardless of however many parameters I send. So that means - as I see it - that I'm going to be sending the maximum number of parameters regardless of whether or not I specify them in my Lua code, because the bindings will have to pass all parameters, unless I checked them all in Lua, which seems messy.
So I'm not really sure if there's an elegant way to do this. Either I check all the parameters to see if they're Nil when they get received in BlitzMax, or I check if they're Nil in the Lua bindings and if they are, I pass less parameters. Neither seems particularly elegant. Is there a better way to do this?
|