user2626195
user2626195

Reputation: 147

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 ?

Upvotes: 6

Views: 620

Answers (2)

lhf
lhf

Reputation: 72312

Yes, you can use lua_iscfunction.

Upvotes: 7

greatwolf
greatwolf

Reputation: 20838

Another possibility is to use lua_tocfunction. This allows you to also check if the C function you got back is the one you expect.

Upvotes: 0

Related Questions