Skip to content

is ​

Type predicates for Lua values and filesystem path types.

Usage ​

lua
is = require "mods.is"

ok = is.number(3.14)       --> true
ok = is("hello", "string") --> true
ok = is.table({})          --> true

NOTE

Function names are case-insensitive.

lua
is.table({})  --> true
is.Table({})  --> true
is.tAbLe({})  --> true

is() ​

is is also callable as is(value, type) to check if a value is of a given type.

lua
is("hello", "string") --> true
is("hello", "String") --> true
is("hello", "STRING") --> true

Functions ​

Type Checks:

FunctionDescription
boolean(v)Returns true when v is a boolean.
function(v)Returns true when v is a function.
nil(v)Returns true when v is nil.
number(v)Returns true when v is a number.
string(v)Returns true when v is a string.
table(v)Returns true when v is a table.
thread(v)Returns true when v is a thread.
userdata(v)Returns true when v is userdata.

Value Checks:

FunctionDescription
false(v)Returns true when v is exactly false.
true(v)Returns true when v is exactly true.
falsy(v)Returns true when v is falsy.
callable(v)Returns true when v is callable.
integer(v)Returns true when v is an integer.
truthy(v)Returns true when v is truthy.

Path Checks:

FunctionDescription
path(v)Returns true when v is a valid filesystem path.
block(v)Returns true when v is a block device path.
char(v)Returns true when v is a character device path.
device(v)Returns true when v is a block or character device path.
dir(v)Returns true when v is a directory path.
fifo(v)Returns true when v is a FIFO path.
file(v)Returns true when v is a file path.
link(v)Returns true when v is a symlink path.
socket(v)Returns true when v is a socket path.

Type Checks ​

Core Lua type checks (type(v) family).

boolean(v) ​

Returns true when v is a boolean.

Parameters:

  • v (any): Value to validate.

Return:

  • isBoolean (boolean): Whether the check succeeds.

Example:

lua
is.boolean(true)

function(v) ​

Returns true when v is a function.

Parameters:

  • v (any): Value to validate.

Return:

  • isFunction (boolean): Whether the check succeeds.

Example:

lua
is.Function(function() end)

nil(v) ​

Returns true when v is nil.

Parameters:

  • v (any): Value to validate.

Return:

  • isNil (boolean): Whether the check succeeds.

Example:

lua
is.Nil(nil)

number(v) ​

Returns true when v is a number.

Parameters:

  • v (any): Value to validate.

Return:

  • isNumber (boolean): Whether the check succeeds.

Example:

lua
is.number(3.14)

string(v) ​

Returns true when v is a string.

Parameters:

  • v (any): Value to validate.

Return:

  • isString (boolean): Whether the check succeeds.

Example:

lua
is.string("hello")

table(v) ​

Returns true when v is a table.

Parameters:

  • v (any): Value to validate.

Return:

  • isTable (boolean): Whether the check succeeds.

Example:

lua
is.table({})

thread(v) ​

Returns true when v is a thread.

Parameters:

  • v (any): Value to validate.

Return:

  • isThread (boolean): Whether the check succeeds.

Example:

lua
is.thread(coroutine.create(function() end))

userdata(v) ​

Returns true when v is userdata.

Parameters:

  • v (any): Value to validate.

Return:

  • isUserdata (boolean): Whether the check succeeds.

Example:

lua
is.userdata(io.stdout)

Value Checks ​

Truthiness, exact-value, and callable checks.

false(v) ​

Returns true when v is exactly false.

Parameters:

  • v (any): Value to validate.

Return:

  • isFalse (boolean): Whether the check succeeds.

Example:

lua
is.False(false)

true(v) ​

Returns true when v is exactly true.

Parameters:

  • v (any): Value to validate.

Return:

  • isTrue (boolean): Whether the check succeeds.

Example:

lua
is.True(true)

falsy(v) ​

Returns true when v is falsy.

Parameters:

  • v (any): Value to validate.

Return:

  • isFalsy (boolean): Whether the check succeeds.

Example:

lua
is.falsy(false)

callable(v) ​

Returns true when v is callable.

Parameters:

  • v (any): Value to validate.

Return:

  • isCallable (boolean): Whether the check succeeds.

Example:

lua
is.callable(function() end)

integer(v) ​

Returns true when v is an integer.

Parameters:

  • v (any): Value to validate.

Return:

  • isInteger (boolean): Whether the check succeeds.

Example:

lua
is.integer(42)

truthy(v) ​

Returns true when v is truthy.

Parameters:

  • v (any): Value to validate.

Return:

  • isTruthy (boolean): Whether the check succeeds.

Example:

lua
is.truthy("non-empty")

Path Checks ​

Filesystem path type checks.

IMPORTANT

Path checks require LuaFileSystem (lfs) and raise an error if it is not installed.

path(v) ​

Returns true when v is a valid filesystem path.

Parameters:

  • v (any): Value to validate.

Return:

  • isPath (boolean): Whether the check succeeds.

Example:

lua
is.path("README.md")

Returns `true` for broken symlinks.

block(v) ​

Returns true when v is a block device path.

Parameters:

  • v (any): Value to validate.

Return:

  • isBlock (boolean): Whether the check succeeds.

Example:

lua
is.block("/dev/sda")

char(v) ​

Returns true when v is a character device path.

Parameters:

  • v (any): Value to validate.

Return:

  • isChar (boolean): Whether the check succeeds.

Example:

lua
is.char("/dev/null")

device(v) ​

Returns true when v is a block or character device path.

Parameters:

  • v (any): Value to validate.

Return:

  • isDevice (boolean): Whether the check succeeds.

Example:

lua
is.device("/dev/null")

dir(v) ​

Returns true when v is a directory path.

Parameters:

  • v (any): Value to validate.

Return:

  • isDir (boolean): Whether the check succeeds.

Example:

lua
is.dir("/tmp")

fifo(v) ​

Returns true when v is a FIFO path.

Parameters:

  • v (any): Value to validate.

Return:

  • isFifo (boolean): Whether the check succeeds.

Example:

lua
is.fifo("/path/to/fifo")

file(v) ​

Returns true when v is a file path.

Parameters:

  • v (any): Value to validate.

Return:

  • isFile (boolean): Whether the check succeeds.

Example:

lua
is.file("README.md")

Returns true when v is a symlink path.

Parameters:

  • v (any): Value to validate.

Return:

  • isLink (boolean): Whether the check succeeds.

Example:

lua
is.link("/path/to/link")

socket(v) ​

Returns true when v is a socket path.

Parameters:

  • v (any): Value to validate.

Return:

  • isSocket (boolean): Whether the check succeeds.

Example:

lua
is.socket("/path/to/socket")