Codectionary / Developer documentation / Lua

Lua table.move ranges

Lua 5.3+ table.move copies an integer-keyed range and safely handles overlap. The destination can be a separate table or the source itself.

Syntax

table.move(source, first, last, targetStart, destination)

Examples

Lua table.move ranges

Run with standalone Lua 5.4: lua example.lua. These scripts target Lua 5.4 rather than Roblox Luau.

local source = {10, 20, 30, 40}
local destination = {5}
table.move(source, 2, 4, 2, destination)
print(table.concat(destination, ","))
print(source[2])
  1. Output: 5,20,30,40, then 20. The source remains intact while indices 2 through 4 are copied.

Best practices

  • Choose bounds explicitly. Copying table-valued elements copies references, not their nested contents.

Runtime & versions

Lua interpreter or a host application. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Lua reference manuals

Specifications & further reading