Skip to content

Standard Lua Environment

Gilberto Romero edited this page Sep 2, 2016 · 2 revisions

By default, all computers will already have all standard Lua libraries and functions. Though, some libraries have been modified in order to maintain security, enhanced to allow for more flexible programming, and added to allow for interacting with the outside environment/interacting with internals. This page will list all differences between the standard Lua environment and the standard computer environment.

Unchanged Libraries and Functions

The following functions and libraries are unchanged:

  • table
  • string
  • coroutine
  • setmetatable
  • getmetatable
  • pairs
  • ipairs
  • select
  • next
  • rawset
  • rawget
  • rawlen
  • rawequal
  • tostring
  • tonumber
  • load
  • pcall
  • xpcall
  • type
  • error
  • assert
  • _VERSION

Modified Libraries

IO

The IO library has been put into a wrapper to keep the accessing of files and directories to the computer's various storage devices only. This includes the following functions:

  • io.open
  • io.lines
  • io.input
  • io.read
  • io.output
  • io.write
  • io.flush
  • io.type (This one has been left alone)

The IO library has also been enhanced with the following functions:

io.list( string path )

Returns: table list

This function will return a table of all files and directories in the given path. Each index in the table (the table being indexed numerically) is a table containing the following values: string name, number size, boolean isDir, string date, string time.

io.exists( string path )

Returns: string type or nil

This will return either "file," "dir," or nil depending on the path it is given, where nil means it doesn't exist.

io.makeDir( string path )

Returns: boolean Success

This will attempt to make a directory at the given path, returning true upon success.

Unimplemented Functions

The following functions have not been implemented in the io library to allow for the computer's OS to implement them instead, if possible:

  • io.stderr
  • io.stdin
  • io.stdout
  • io.popen
  • io.tmpfile

OS

Some parts of the os library has also been put into a wrapper to ensure consistency. Those functions are as follow:

  • os.clock
  • os.remove
  • os.rename

The following functions have been implemented without any kind of wrapper:

  • os.date
  • os.difftime
  • os.time

The following functions have not been implemented, leaving it up to the computer's OS to do so:

  • os.getenv
  • os.setenv
  • os.execute
  • os.exit
  • os.tmpname

Package

The package library has been severely cut, with only the two following tables implemented:

  • package.loaded
  • package.preload

The following functions have not been implemented, but some may at a later date:

  • package.config
  • package cpath
  • package.path
  • package.searchpath
  • package.searchers
  • package.loadlib

Math

Almost the entire math library has been put in as-is, without any modification. However, the following functions have been put into a wrapper to ensure the computer's environment stays within it's bounds:

  • math.randomseed
  • math.random

Modified Functions

The following functions have been reimplemented to use the io wrapper:

  • loadfile
  • dofile
  • require

Clone this wiki locally