is it possible to list all functions in a program
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
list all functions
Started by darkhenmore, 08 September 2012 - 01:53 PMPosted 08 September 2012 - 03:53 PM
hi,
is it possible to list all functions in a program
is it possible to list all functions in a program
Posted 08 September 2012 - 04:17 PM
hi,
is it possible to list all functions in a program
Yes, when they are your functions I would just do it like this
print("FooFunction(arg1, arg2, arg3) #This is a Description what the Function does!")
and then for every function the same.This way you need to write everythin your self for every function. Maybe there is a function to do this.
But im sure you can do it easier.
Posted 08 September 2012 - 04:25 PM
thanks but i have about 50 functions in a program and im adding more constantly. so i need somthing that will automatically do it.
Posted 08 September 2012 - 04:30 PM
If they're not local functions, you could use _G, which is a global table containing all variables. You might get some like sleep() or read() doing this, though.
You can print the function name, but not it's code or function automatically (at least as far as I know.)
for i,v in pairs(_G) do
if type(v) == 'function' then
print(i)
end
end
You can print the function name, but not it's code or function automatically (at least as far as I know.)
Posted 08 September 2012 - 05:57 PM
thanks for the help but i just thought of a better way to do it. you use gmatch. make it look for "function" then a space then some characters.
Posted 11 September 2012 - 06:58 AM
very smart. but are you using this as an API? if so them it will be assigned a name (the filename of the API), then just use the code
and you have your list
for k,v in pairs(apiname) do
print(k)
end
and you have your list
Posted 11 September 2012 - 01:13 PM
I never understood why people used "k,v" instead of "i,v"
I know i stands for index but what does k mean?
I know i stands for index but what does k mean?
Posted 11 September 2012 - 02:59 PM
I never understood why people used "k,v" instead of "i,v"
I know i stands for index but what does k mean?
probably k = key, v = value
Posted 12 September 2012 - 07:20 AM
I think everyone just uses it because they are familiar with it, it is the one Dan200 uses and I'm guessing everyone started by reading his code
Posted 12 September 2012 - 07:24 AM
No, it's used like that in the Lua documentation too. It's key, value.
Posted 12 September 2012 - 08:33 AM
ah, ok… I was not aware of that. to be honest I do not know why I use it