   lua_pcall hooking
  Hi guys,i'm trying to hook lua_pcall in a game to find the lua functions that the games executes (the lua scripts are compiled).I managed already to hook completely this function, now i'm trying to get the function name and args for the called lua function.This is the code:  int top=lua_gettop(a2);  char *temp;  temp=lua_tostring(a2, v7);  if(temp)  {debug2<<"Pcall: "<<temp<<endl;  for ( int n=v7+1; n<=(top); n++ ) {temp=lua_tostring(a2, n);if(!temp)temp="";cout << "-- argument " << n << ": "<< temp << std::endl;}  debug2<<"---------------------------------"<<endl;  }  debug2.flush();The problem is that lua_tostring always returns 0 (v7 is the index of the function that is going to be called).It's strange....can someone explain me why it isn't working?Roby   
  A function isn't a string. One way to get a "name" for a function is to search the lua globals table (recursively) for a value equal to the function in question, then use the string value of the key (if it is even a string - the key could be anything).A function might have many names, it might have no "name" (as in a string, it might be identified by something else):_G[[1]] = function()print "Hello World" end_G[[1]]()function foo()print "What's my name?"endbar = foofoo()bar()for k,v in pairs(_G) do   print ("\t" .. tostring(k) .. " -> " .. tostring(v))endA frequent way of using Lua is to implement callbacks, these functions won't have a global name as they are often associated with the "self" parameter. It might be worth searching the first parameter, if it is a table, to obtain a name.   ;  I don't understand what you are suggesting me...AFAIK when i need to call a lua function inside a script, i do something like this:lua_getglobal(L,"function_name");lua_pcall(L,0,0,0);So, i need to know the "function_name" inside lua_pcall...(I can't hook every single getglobal because it is a define)   ;  That's not always the case. Functions aren't named in Lua, but can used as a value in a table. Which is exactly how global functions work; _G is just a "special" Lua table used for globals. Consider the following:In Lua:SomeCFunction(function() print("what is my name?") end)In C:int SomeCFunction(lua_State* L){   lua_pcall(L, 0, 0, 0);   return 0;}This is perfectly legal (and common), and the function is never assigned a name.   