Reine Elemente
Reine Elemente

Reputation: 131

How do i pass a table parameter to a function created with load?

Not using load, i would have this source:

function dosearch(t)
   t:search()
end

and call it with

dosearch(my_search_t)

However, i want to use load to evaluate a string with the above code inside.

codestr = "t:search()"
searchfunc = load(codestr)

And finally call it:

function callsearch(t)
  -- How to use debug.setupvalue to pass t?
 searchfunc()
end

How do i use debug.setupvalue to pass t?

Upvotes: 0

Views: 98

Answers (1)

Egor   Skriptunoff
Egor Skriptunoff

Reputation: 974

function dosearch(t)
   t:search()
end

is equivalent to

dosearch = load [[
  local t = ...
  t:search()
]]

Upvotes: 2

Related Questions