Library builtin

Built in values. These don't need to be loaded; they are in the default environment.

Functions

assert (condition, msg) Same as Lua's assert.
concmd (cmd) Execute a console command
dofile (file) Runs an included script, but does not cache the result.
error (msg) Throws a raw exception.
getLibraries () Gets a list of all libraries
getfenv () Simple version of Lua's getfenv Returns the current environment
getmetatable (tbl) Same as Lua's getmetatable.
ipairs (tbl) Same as Lua's ipairs
iter (typ) Used the same as Lua's pairs but iterates over the given library's or type's default fields
loadstring (str) GLua's loadstring Works like loadstring, except that it executes by default in the main environment
next (tbl, k) Same as Lua's next
pairs (tbl) Same as Lua's pairs
print (...) Prints a message to the player's chat.
printTable (tbl) Prints a table to player's chat
quotaAverage () Gets the Average CPU Time in the buffer
quotaMax () Gets the CPU Time max.
quotaUsed () Returns the current count for this Think's CPU Time.
require (file) Runs an included script and caches the result.
setfenv (func, tbl) Lua's setfenv Works like setfenv, but is restricted on functions
setmetatable (tbl, meta) Same as Lua's setmetatable.
throw (msg, level, uncatchable) Throws an exception
tonumber (obj) Same as Lua's tonumber
tostring (obj) Same as Lua's tostring
try (func, catch) Try to execute a function and catch possible exceptions Similar to xpcall, but a bit more in-depth
type (obj) Same as Lua's type
unpack (tbl) Same as Lua's unpack

Tables

math Lua's ( not GLua's ) math library, plus clamp, round, and randfloat
os GLua's os library.
string Lua's (not GLua's) string library
table Lua's (not GLua's) table library

Fields

CLIENT Constant that denotes whether the code is executed on the client
SERVER Constant that denotes whether the code is executed on the server


Functions

SF.DefaultEnvironment.assert (condition, msg)
Same as Lua's assert.

Parameters:

  • condition:
  • msg:
SF.DefaultEnvironment.concmd (cmd)
Execute a console command

Parameters:

  • cmd: Command to execute
SF.DefaultEnvironment.dofile (file)
Runs an included script, but does not cache the result. Pretty much like standard Lua dofile()

Parameters:

  • file: The file to include. Make sure to --@include it

Return value:

    Return value of the script
SF.DefaultEnvironment.error (msg)
Throws a raw exception.

Parameters:

  • msg: Exception message
SF.DefaultEnvironment.getLibraries ()
Gets a list of all libraries

Return value:

    Table containing the names of each available library
SF.DefaultEnvironment.getfenv ()
Simple version of Lua's getfenv Returns the current environment

Return value:

    Current environment
SF.DefaultEnvironment.getmetatable (tbl)
Same as Lua's getmetatable. Doesn't work on most internal metatables

Parameters:

  • tbl: Table to get metatable of

Return value:

    The metatable of tbl
SF.DefaultEnvironment.ipairs (tbl)
Same as Lua's ipairs

Parameters:

  • tbl: Table to iterate over

Return values:

  1. Iterator function
  2. Table tbl
  3. 0 as current index
SF.DefaultEnvironment.iter (typ)
Used the same as Lua's pairs but iterates over the given library's or type's default fields

Parameters:

  • typ: The Starfall Library or Type to iterate over

Usage:

    -- Default Environment, would also work with getfenv() 
     
    for k, v in iter( _G ) do 
       -- CODE 
    end 
     
    -- or for example: 
     
    for k, v in iter( render ) do 
       -- CODE 
    end
SF.DefaultEnvironment.loadstring (str)
GLua's loadstring Works like loadstring, except that it executes by default in the main environment

Parameters:

  • str: String to execute

Return value:

    Function of str
SF.DefaultEnvironment.next (tbl, k)
Same as Lua's next

Parameters:

  • tbl: Table to get the next key-value pair of
  • k: Previous key (can be nil)

Return values:

  1. Key or nil
  2. Value or nil
SF.DefaultEnvironment.pairs (tbl)
Same as Lua's pairs

Parameters:

  • tbl: Table to iterate over

Return values:

  1. Iterator function
  2. Table tbl
  3. nil as current index
SF.DefaultEnvironment.print (...)
Prints a message to the player's chat.

Parameters:

  • ...: Values to print
SF.DefaultEnvironment.printTable (tbl)
Prints a table to player's chat

Parameters:

  • tbl: Table to print
SF.DefaultEnvironment.quotaAverage ()
Gets the Average CPU Time in the buffer

Return value:

    Average CPU Time of the buffer.
SF.DefaultEnvironment.quotaMax ()
Gets the CPU Time max. CPU Time is stored in a buffer of N elements, if the average of this exceeds quotaMax, the chip will error.

Return value:

    Max SysTime allowed to take for execution of the chip in a Think.
SF.DefaultEnvironment.quotaUsed ()
Returns the current count for this Think's CPU Time. This value increases as more executions are done, may not be exactly as you want. If used on screens, will show 0 if only rendering is done. Operations must be done in the Think loop for them to be counted.

Return value:

    Current quota used this Think
SF.DefaultEnvironment.require (file)
Runs an included script and caches the result. Works pretty much like standard Lua require()

Parameters:

  • file: The file to include. Make sure to --@include it

Return value:

    Return value of the script
SF.DefaultEnvironment.setfenv (func, tbl)
Lua's setfenv Works like setfenv, but is restricted on functions

Parameters:

  • func: Function to change environment of
  • tbl: New environment

Return value:

    func with environment set to tbl
SF.DefaultEnvironment.setmetatable (tbl, meta)
Same as Lua's setmetatable. Doesn't work on most internal metatables

Parameters:

  • tbl: The table to set the metatable of
  • meta: The metatable to use

Return value:

    tbl with metatable set to meta
SF.DefaultEnvironment.throw (msg, level, uncatchable)
Throws an exception

Parameters:

  • msg: Message
  • level: Which level in the stacktrace to blame. Defaults to one of invalid
  • uncatchable: Makes this exception uncatchable
SF.DefaultEnvironment.tonumber (obj)
Same as Lua's tonumber

Parameters:

  • obj:

Return value:

    obj as number
SF.DefaultEnvironment.tostring (obj)
Same as Lua's tostring

Parameters:

  • obj:

Return value:

    obj as string
SF.DefaultEnvironment.try (func, catch)
Try to execute a function and catch possible exceptions Similar to xpcall, but a bit more in-depth

Parameters:

  • func: Function to execute
  • catch: Function to execute in case func fails
SF.DefaultEnvironment.type (obj)
Same as Lua's type

Parameters:

  • obj: Object to get type of

Return value:

    The name of the object's type.
SF.DefaultEnvironment.unpack (tbl)
Same as Lua's unpack

Parameters:

  • tbl:

Return value:

    Elements of tbl

Tables

SF.DefaultEnvironment.math
Lua's ( not GLua's ) math library, plus clamp, round, and randfloat

SF.DefaultEnvironment.os
GLua's os library. http://wiki.garrysmod.com/page/Category:os

SF.DefaultEnvironment.string
Lua's (not GLua's) string library

SF.DefaultEnvironment.table
Lua's (not GLua's) table library

Valid XHTML 1.0!