Skip to content

Latest commit

 

History

History
55 lines (49 loc) · 1.7 KB

documentation.md

File metadata and controls

55 lines (49 loc) · 1.7 KB

Functions

readScript ( script, environment, removeComments )

Loads a given string in a given environment.
removeComments determines whether or not to remove comments before reading. (Default is true)

Example:

local loader = require("luayan")

loader.readScript( [[
  local str = "Hello"
  print(str..", World!") --Hello, Word!
]], _G)

readLine ( script, environment )

Loads the first line or block of code in an environment.
Returns the remaining script.

Example:

local loader = require("luayan")

local script = loader.readLine( [[
  print( ({ a = 0,
            b = 1 }).a )
  print("Hello, Word!")
]], _G) --prints 0.

print(script) --prints [[print("Hello, World!")]]

readExpression ( script, environment, unary )

Evaluates an expression in an environment.
Returns the remaining script after the expression and the expression value(s)
If unary is true, it will stop before the first operator (unless it's the '^' operator)

Example:

local loader = require("luayan")

print( loader.readExpression( [[1 + 8 / 2 example]], {}, false ) )
--prints " example", 5

print( loader.readExpression( [[1 + 8 / 2 unary example]], {}, true ) )
--prints " + 8 / 2 unary example", 1

removeComments ( script, keepLines )

Removes all the comments in a script.
keepLines determines whether or not to keep the same amount of lines of multi-line comments. (Default is false)
Returns the script without comments.

Example:

local loader = require("luayan")

print( loader.removeComments [=[ local a = "example -- string" -- [[ some
comment 
here ]] ]=] )
--prints [[ local a = "example -- string"  ]]