lua-users home
lua-l archive

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

Hi I assume you are talking about a Lua function written in C using the C API, called from Lua (or from C via the API).

In this case, in your function the parameters will be on the stack in first/second/third order (if you had 3 params). Push your results on the stack and return how many results you are returning. Lua will take care of the rest.

So if you have one param and return one result, you can push your result on top of your param and return 1, you don't need to pop the param first. If you want to return two results, push them both and return 2.

The only catch is you have to ensure there is enough stack space if you are using the stack a lot.

On Mon, Nov 11, 2013 at 12:30 PM, Tim Channon <> wrote:
Can someone please clarify fundamental stack behaviour.

I am writing a significant Lua binary library.

abc = mylib(table)

On entry to the C the Lua stack contains one parameter item.

On return from C there is one new item created by the C library.

Behaviour question:- Should the C remove the original item or leave it
in place? (if left in place, what parameter count should be returned?)

All working nicely so far.
Parses trace of graphics plot supplied as PNG into table of numbers,
optionally rescaling x and y axis to requested ranges.
I have yet to decide whether to include the associated simple OCR
(currently in Lua, to be recoded) which is in daily usage reading
autoscaled plot axis. (provides the requested axis range)