lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 8/04/2011, at 9:24 PM, C++ RTMP Server wrote:

>> Nope.  All you can really do is see if the function exists.  It's up to
>> the function itself to check the paramters it gets.  
> My scenario is the other way around. I let the user define a lua callback function. I know the if he defines myHandlerForMyCustomEvent function, I should call it from the C++ when MyCustomEvent is triggered. Now, before calling it from C/C++, what I would like is to see if, at least, has the proper number of arguments (if determining the type is not possible). Otherwise, the user is bound to make mistakes. If C/C++ expects myHandlerForMyCustomEvent function to have 3 params and the user defines that function with only 1 parameter, I would like to warn him/her before continuing: 
> 
> "Hey, myHandlerForMyCustomEvent function is not defined properly for C/C++ needs! It will definitely not do the job because you missed 2 params"


You could use lua_getinfo to get the firstlinedefined for the function, and then parse that yourself to see if it meets your requirements.  Or you could use lua_getlocal to get the names of the first few *local variables* - they might or might not be parameters, and I don't think you can tell - and check their names.

Alternatively, you could just call the function with dummy arguments before you start using it properly and check that it doesn't crash.

I'm not saying any of these are particularly good ideas.

Cheers,
Geoff