简体   繁体   中英

LUA 5.1 how do i get the calling variable from a function?

function newpos(xScale, xOffset, yScale, yOFfset)
    print(f.Position)
end

local f = {}
f.Position = 1
f.Size = newpos(1, 0, 1, 0)
f.Filled = true
f.Visible = true

how do i get the f table from newpos?

how do i get the f table from newpos

If you want to get a table from a function that function needs to return that table.

Let's say you want to create a table that represents a 2d point:

function newpos(x, y)
  local p = {
    x = x,
    y = y,
  }
  return p
end

Then you can do something like

local origin = newpos(0, 0)
print(origin.x, origin.y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM