Jump to content

Functions as Strings


ShayF2

Recommended Posts

function getAllFunctions()
    local funcs = {}

    local function dump(t)
        for k, v in pairs(t) do
            --[[if type(v) == 'table' then
                dump(v)
            else]]if type(v) == 'function' then
                funcs[k] = v
            end
        end
    end
    dump(_G)
    print('hi')
    
    return funcs
end

function getFunctionFromName(name)
  local t = getAllFunctions()-- first run here
  if type(name) == 'string' then
    if t[name] then
      return t[name]
    end
  end
  return false
end

local GAF = getFunctionFromName('getAllFunctions')
GAF()-- second run here.

I'm trying to do stuff like this for string modification, loading external (not included) files, and other crazy stuff, this is really just for test purposes. Stack Overflow error occurs when repeating the same action to child tables.
Does anyone have a way around this?

Edited by ShayF
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...