-2

Here is a function name register closure which I use to register library names:

The Pool object:

function FooBarPool()
  local Names = {}
  local self = {}
    function self:Register(fFoo,sName)
      if(fFoo) then
        Names[fFoo] = sName
      end
    end
    function self:GetName(fFoo)
      return Names[fFoo] or "N/A"
    end
  return self
end

Create a Pool object

local Pool = FooBarPool()

Register known library functions

Pool:Register(string.sub,"string.sub")
Pool:Register(string.gsub,"string.gsub")
Pool:Register(string.match,"string.match")
Pool:Register(string.gmatch,"string.gmatch")
Pool:Register(string.find,"string.find")
Pool:Register(string.gfind,"string.gfind")
Pool:Register(string.format,"string.format")
Pool:Register(string.byte,"string.byte")
Pool:Register(string.char,"string.char")
Pool:Register(string.len,"string.len")
Pool:Register(string.lower,"string.lower")
Pool:Register(string.upper,"string.upper")
Pool:Register(string.rep,"string.rep")
Pool:Register(string.reverse,"string.reverse")

for k,v in pairs(string) do
  print(tostring(v) .. " : "..Pool:GetName(v))
end
  • 1
    Please edit your question and to put all info here and delete that "false" answer. Also you can go to http://stackoverflow.com/help and learn how to use this site, welcome to SO by the way – jean Feb 03 '15 at 10:16

2 Answers2

2

If you add print(k,v) to your last loop, you'll see that you're missing string.dump.

The function string.gfind is not standard. It was present in Lua 5.0 but was renamed to string.gmatch in Lua 5.1.

You can get all the names in the string library with

for k in pairs(string) do
    print(k)
end

or see the manual.

lhf
  • 70,581
  • 9
  • 108
  • 149
  • Yes i know ... duhh just wanted to try out if that's the so called "phantom" function – Деян Добромиров Feb 03 '15 at 10:23
  • Finally the answer I was looking for I am Asking IS that was TOO HARD than everyone have to hate everybody here ... God speed m8 – Деян Добромиров Feb 03 '15 at 10:55
  • @Деян Добромиров it's not rage. This is a Q&A site, not a forum and the community try to keep it sanitized and on tracks to keep it clean and organized. You and your questions are welcome, just try to follow de rules – jean Feb 03 '15 at 17:43
  • Yeah, sure I just don't get this. Why they have to vote down for my code . It's just a code and output .... Not that I care or anything. So you do your super-duper amazing code which does all kinds of stuff and the people star hating it for not particular reason. Correct me if I am wrong. – Деян Добромиров Feb 04 '15 at 07:32
0

Why not list the string library string functions in an array and then iterate them using the pairs function, thus: strings = {"string.sub", "string.gsub", ..., "string.reverse"}; for _k,v in pairs(strings) do print(v) end; I find this is easier than the answers given above. BTW is there a better method to unpack all the string library string functions without resorting to listing them in a table?