Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if function is in C or Lua implemented

I've created a table and assigned a method with lua_pushcfunction named mytable:myfunction(). In a different (callback) context it's necessarily that myfunction will be overriden inside the Lua script. For some reasons, if i call myfunction from the C host, I need to know, if myfunction is still the c function or was replaced by the script.

Is there a way to test (from C), if the C method is still attached or is replaced by some Lua code ?

like image 742
user2626195 Avatar asked Aug 12 '13 10:08

user2626195


People also ask

Can Lua use C?

The C API is the set of functions that allow C code to interact with Lua. It comprises functions to read and write Lua global variables, to call Lua functions, to run pieces of Lua code, to register C functions so that they can later be called by Lua code, and so on.

How do you call a function in C Lua?

Moreover, for a C function to be called from Lua, we must register it, that is, we must give its address to Lua in an appropriate way. When Lua calls a C function, it uses the same kind of stack that C uses to call Lua. The C function gets its arguments from the stack and pushes the results on the stack.

What is %f Lua?

In Lua, the following are the available string formatting syntax or string literals for different datatypes: %s : This serves as a placeholder for string values in a formatted string. %d : This will stand in for integer numbers. %f : This is the string literal for float values.

Can you call a function within a function Lua?

Functions can be defined from anywhere in a program, including inside other functions, and they can also be called from any part of the program that has access to them: functions, just like numbers and strings, are values and can therefore be stored in variables and have all the properties that are common to variables.


1 Answers

Yes, you can use lua_iscfunction.

like image 151
lhf Avatar answered Oct 16 '22 10:10

lhf