Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are obviously interested in a <a href="http://en.wikipedia.org/wiki/Variadic_function" rel="nofollow">variadic function</a>, but the trouble is determining the type of the arguments to push onto the Lua stack. I'll recommend a couple approaches:</p> <ol> <li><p>The first would be to include a format string a la the <a href="http://en.wikipedia.org/wiki/Printf" rel="nofollow">printf</a> family or binary packing formats often used in higher level languages. For example, take a look at the format pattern used in the <a href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpack" rel="nofollow">lpack</a> Lua module. The key is to scan through the format string to determine how many and what kind of arguments are provided.</p></li> <li><p>Alternatively, you could implement a <a href="http://en.wikipedia.org/wiki/Variant_type" rel="nofollow">variant</a> type. Each argument would need to be wrapped in such a structure. Also, the total number of arguments would need to be provided as the first parameter.</p></li> <li><p>Finally, you could pass arguments in two arrays instead of using a variadic function. The first array would contain the enumerated types corresponding to the target of <code>void *</code> pointers in the second array. This method requires the most house keeping for client code, but is fairly clean. Either an argument specifying the length of the arrays or a sentinel value at the end of one or both array would be required as well.</p></li> </ol> <p>Hopefully, one of those methods should work out for you. Personally, I would go with the first option and use the <a href="http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpack" rel="nofollow">lpack</a> code as a guide. It comes the closest to the function signature specified in your question as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload