Gammon Forum
Entire forum
MUSHclient
Lua
Is there any way to...?
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Cage_fire_2000
USA (119 posts) bio
|
Date
| Thu 11 Sep 2008 07:57 PM (UTC) |
Message
| 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? | top |
|
Posted by
| David Haley
USA (3,881 posts) bio
|
Date
| Reply #1 on Thu 11 Sep 2008 08:15 PM (UTC) |
Message
| 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. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|
Posted by
| Cage_fire_2000
USA (119 posts) bio
|
Date
| Reply #2 on Thu 11 Sep 2008 08:56 PM (UTC) |
Message
| 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? | top |
|
Posted by
| David Haley
USA (3,881 posts) bio
|
Date
| Reply #3 on Thu 11 Sep 2008 09:13 PM (UTC) |
Message
| 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. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|
Posted by
| Nick Gammon
Australia (23,000 posts) bio
Forum Administrator |
Date
| Reply #4 on Thu 11 Sep 2008 09:37 PM (UTC) |
Message
|
Quote:
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). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,746 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.