Is there any way of itering through values of a table, and if it contains a function display the arguments to that function? Like if I were to iterate through the 'world' table, to show information about its contents, say it came across... the ColourNote function, is there a way I could have it print out... ColourNote(TextColour, BackgroundColour, Text) or does Lua even record the names of the arguments, I suppose it could just pass arguments in whatever order they're given, if so, does it at least record how many arguments it takes? Are there any information gathering functions for functions?
Is there any way to...?
Posted by Cage_fire_2000 on Thu 11 Sep 2008 07:57 PM — 5 posts, 22,056 views.
See:
http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo
Not the most user-friendly way of doing things, but I think it's the only way to do what you want.
http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo
Not the most user-friendly way of doing things, but I think it's the only way to do what you want.
Yeah, that doesn't give me anything about arguments, the only really useful thing is it shows whether it's written in C or Lua. See, I'm trying to create a function to walk through the tables and display information about the elements. Just as a learning exercise although I'm finding that the _G and package tables seem to have circular references which lead to infinite recursion, so I had to filter them out. BTW, is there any key combo to halt a runaway script in MUSHclient? Besides Alt-Ctrl-Del?
Oh -- right, I answered before thinking about this too much. I think it's actually impossible to know the arguments of a function defined in C. After all, all Lua knows is where the prototype is. The notion of "arguments" is determined by how that function pops things off of the stack. I think that if the function were being defined in a source file, you could get the contents based on the line number and source, but obviously that won't work for functions defined in C.
Quote:
BTW, is there any key combo to halt a runaway script in MUSHclient? Besides Alt-Ctrl-Del?
BTW, is there any key combo to halt a runaway script in MUSHclient? Besides Alt-Ctrl-Del?
Not a key combo, but see:
http://www.gammon.com.au/forum/?id=6534
As for the arguments, as Lua gets arguments procedurally (rather than by table lookup), no there is no way of finding what arguments a function expects. Indeed, some functions can pull arguments out in odd ways (for example, get the first argument, and then decide, based on its type, what to fetch next).
Also, some functions take an indefinite number of arguments (eg. print, string.format, ColourNote, just to name a few).