-2

Is there any way to count the amount of lua_getfield that exists in my code? If yes how?

I have a code with multiple lua_getfield as an example below:

lua_getfield(L, -1, "MAC");
lua_getfield(L, -1, "IP");
lua_getfield(L, -1, "PASSWORD");

I want to create a message to show the amount of lua_getfield being made reading the code in my C program, for example:

printf("There are %d lua_getfield", function);
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Marcos Silva
  • 53
  • 1
  • 6
  • 2
    You asked this question the other day didn't you? You got some comments and suggestions in the comments. What happened to that question? – Etan Reisner Nov 10 '15 at 16:12
  • Yesterday was poorly explained, then deleted. – Marcos Silva Nov 10 '15 at 16:52
  • I'm fairly certain your question yesterday was **identical** to this one (though I can't check obviously). Deleting and starting a new question also loses any value the comments on the previous question provided (and there was some). – Etan Reisner Nov 10 '15 at 17:14

1 Answers1

0

count the amount

The amount of what?

The number of call sites in your source code? Use grep or a static analysis tool.

The number of calls at runtime? Add a counter to the function or use a profiling tool.

Mud
  • 28,277
  • 11
  • 59
  • 92
  • I have a very extensive lua code, I want to count how many lua_getfield functions exist, and put in a message – Marcos Silva Nov 10 '15 at 16:55
  • @MarcosSilva You want to count how many times the string `lua_getfield` appears in the source code? Use `grep`. If you mean something else then **add those details** to the question. – Etan Reisner Nov 10 '15 at 17:14
  • That, plus I want to notify it in a message, and the grep will be possible only I see, what I want and when my program starts it show a message. for example: `There are %d lua_getfield in file test.c` – Marcos Silva Nov 10 '15 at 17:33