Garry's Mod Wiki

no value

no value is a type in Lua representing no data. While this mostly appears the same as nil from the Lua state, C functions will consider this distinct. This difference can be displayed from Lua with the type function which, unlike vanilla Lua's type function, will return no value when given no data.

Example

Examples of the difference:

print( type() ) print( type( nil ) )
Output:
no value
nil

In vanilla Lua 5.1-5.3, calling type() will result in the error bad argument #1 to 'type' (value expected) instead of returning no value, making this property unique to GLua.

Functions that return nothing technically return no value, making return and return nil unique statements.

Example

Examples of the difference:

local function a() end -- Same as a local function b() return end -- Difference from a and b local function c() return nil end print( type( a() ) ) print( type( b() ) ) print( type( c() ) )
Output:
no value
no value
nil

Lua variables cannot hold no value and instead will default to nil.

Example

Example of this behaviour:

local function a() end local d = a() print( type( d ) )
Output: nil

no value will be coerced to nil in value comparisons.

Example

Example of this behaviour:

local function a() end print( a() == nil ) print( not a() )
Output:
true
true

Page Links


Special Pages


Wikis

?

Render Time: 87ms

DB GetPage 53
Generate Html 10
SaveChanges (1) 9
Render Body 0
Render Sidebar 12