0x59
0x59

Reputation: 87

How would I make a function and insert it into a table

I have a function that will create a function and insert that function in the table it somewhat goes like this.

local Events = {}
Events.Functions = {}

Events.AddEvent = function(code1)
    local Event = function(code1)
        loadstring(code1)
    end
    table.insert(Events.Functions, Event)
end

Events.AddEvent("print(\"hello\")")

Upvotes: 2

Views: 594

Answers (1)

Yu Hao
Yu Hao

Reputation: 122373

loadstring (or load in Lua 5.2 or higher) itself returns a function, you don't need the extra function when defining Event:

local Event = loadstring(code1)
table.insert(Events.Functions, Event)

Or simply:

table.insert(Events.Functions, loadstring(code1))

Upvotes: 2

Related Questions