lua-users home
lua-l archive

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


On Apr 8, 2011, at 12:11 PM, Sean Conner wrote:

> It was thus said that the Great C++ RTMP Server once stated:
>> Hello all,
>> 
>> I'm just trying the depth of the ocean with my finger here...
>> 
>> Is it somehow possible to validate the number/types of parameters for lua
>> functions from C/C++? More details ...
>> 
>> 
>> I already embedded lua as scripting engine in my project. What I do is to
>> load the lua script, inspect the existence of certain lua functions in the
>> script and if they exists I will call them when the time comes. Now, is it
>> possible to also introspect/reflect on the number/types of parameters?
>> 
>> Some pseudo code:
>> 
>> if unable to load lua script
>> 	return false
>> 
>> foreach functionName in functionsNamesList do
>> 	if functionName doesn't exist //this works just fine
>> 		continue
> 
>  Yes, this you can do.
> 
>> 	if functionName parameters count different from expected //maybe possible
>> 		continue
> 
>  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"


> 
>> 	if functionName parameters types different from expected //I bet that this is not possible....
>> 		continue
> 
>  Nope.
> 
>> 	mark function as callable
>> done
> 
> 
>> Bottom line:
> 
>> Is there any lua api for further describe a LUA_TFUNCTION in greater
>> detail? (parameters count, types, return type, etc)? Even if I have only
>> parameters count is still better than nothing.
> 
>  Sorry, all you can do is see if it's a function, and when it's time to
> call it, push what you think is the appropriate data onto the Lua stack and
> call it.  
> 
>  -spc
> 
> 

------
Eugen-Andrei Gavriloaie
Web: http://www.rtmpd.com