1

I have a piece of lua code that is called from a C program that passes it a table.

The table contains a table which has a field that LUA reports is of type "function".

I want to invoke that function and get its return value, but the following just causes a crash (????stack corruption????):

function myFunc (tableIn)
    local interface = tableIn["interface"] -- type(interface) is table
    local targetFunc = interface["targetFunc"] -- type(targetFunc) is function
    local value = targetFunc()
    ...
end

I'm therefore assuming that I need to pass one or more parameters to targetFunc(...) but I have no idea what targetFunc() is expecting and I don't have access to the documentation or code for targetFunc - which I'm also guessing is written in C.

I've seen the thread lua - get the list of parameter names of a function, from outside the function and run the code as suggested - but that just seems to return "*temporary".

The question: is there some "standard" way of calling a C routine from LUA - or is there any other programmatic way (even a one-off) of finding out how many and what type of parameters targetFunc(...) needs.

Even an answer of "no - you need to see the code / doc for targetFunc(...)" would help!

Thanks in advance...

LucyLa
  • 43
  • 4
  • 3
    I'm not aware of any way to achieve that. but if you don't know what a function does nor what it's parameters are, what's the point of calling it? are you reverse engineering something? – Piglet Aug 12 '21 at 11:21
  • Lua by itself is not supposed to crash for whatever reason: it can fail to compile or throw an error at runtime, but not crash. This implies there is a bug in the C implementation, and you didn't show its code. – prapin Aug 12 '21 at 20:24
  • Thanks Piglet and Prapin -- I know what it's meant to do! (It should be / return a "number" without needing any input parameters). And your insight leads me to the conclusion that I do need to get hold of the code / doc for targetFunc(...) ... I had hoped to avoid bothering the developer but here goes! Thanks again. Case closed! – LucyLa Aug 13 '21 at 09:32

0 Answers0