Difference between revisions of "Require"

From ComputerCraft
Jump to navigation Jump to search
(Create an initial template for require)
(No difference)

Revision as of 14:50, 30 January 2020

require
Function
Syntax
require()
Returns anything
API shell
Source CC:Tweaked

Searches for a module on the current library path, returning the module or raising an error if it cannot be found.

ExampleExampleLoading the cc.expect library
Loads the built-in cc.expect module, and uses it within a function
Code
local expect = require("cc.expect").expect
local function check_string(x)
  expect(1, x, "string")
end

check_string(123)
Output
bad argument #1 to 'check_string' (expected string, got number)