Skip to main content

Metatable

Metatable support for the sandboxed environment.


Functions​

setmetatable​

sm.scrapcomputers.metatable.setmetatable( tbl, metatable )

Sets the metatable of a table.

warning

This does not modify tbl. It returns a new table (a copy of tbl's contents) with the metatable applied, so always use the returned value.

Passing a table that was returned by this function changes its metatable in place. If the current metatable has a __metatable field, it is protected and an error is thrown.

Arguments:

  • tbl [ table ] The table to apply the metatable to.
  • metatable [ table? ] The metatable data. If nil, the metatable is removed.

Returns:

  • [ table ] The table with the metatable applied.

getmetatable​

sm.scrapcomputers.metatable.getmetatable( tbl )

Returns the metatable of a table (or its __metatable field if set). Only works on tables returned by setmetatable.

Arguments:

  • tbl [ table ] The table to get the metatable from.

Returns:

  • [ table? ] The metatable, or nil if it has none.

rawget​

sm.scrapcomputers.metatable.rawget( tbl, key )

Gets a value without triggering __index.

Arguments:

  • tbl [ table ] The table to read from.
  • key [ string|number ] The key.

Returns:

  • [ any ] The raw value.

rawset​

sm.scrapcomputers.metatable.rawset( tbl, key, value )

Sets a value without triggering __newindex.

Arguments:

  • tbl [ table ] The table to write to.
  • key [ string|number ] The key.
  • value [ any ] The value.

Returns:

  • [ table ] The table.

rawlen​

sm.scrapcomputers.metatable.rawlen( tbl )

Gets the length of a table without triggering __len.

Arguments:

  • tbl [ table ] The table.

Returns:

  • [ integer ] The raw length.