Difference between revisions of "Require"

From ComputerCraft
Jump to navigation Jump to search
(Create an initial template for require)
 
m (Add external links)
Line 20: Line 20:
 
     }}
 
     }}
 
}}
 
}}
 +
 +
==External links==
 +
*[http://lua-users.org/wiki/ModulesTutorial Lua Module tutorial]
 +
*[https://www.lua.org/manual/5.1/manual.html#pdf-require Lua manual for '''require''']

Revision as of 14:53, 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)

External links