Skip to content

Latest commit

 

History

History
311 lines (152 loc) · 3.86 KB

Luar.md

File metadata and controls

311 lines (152 loc) · 3.86 KB

Raudius\Luar\Luar

Methods

Name Description
__construct
addCoreLibrary Adds a "core" library.
addLibrary Adds a library to the interpreter.
assign Injects a variable or function into the global scope.
call Calls a function in the global scope.
callLuarClosure Calls a closure generated by Luar.
eval Evaluates a Lua program.
getGlobals Returns all the variables in the global scope as an array.
packLuarObject Converts any PHP object to a LuarObject
unpackLuarObject Converts a LuarObject to a PHP object

Luar::__construct

Description

 __construct (void)

Parameters

This function has no parameters.

Return Values

void


Luar::addCoreLibrary

Description

public addCoreLibrary (\Library $library)

Adds a "core" library.

Core library functions get added directly to the root scope and no meta-methods are expected.

-- non-core library function example: `string.lower()`  
string.lower('HeLlO, wORLd!')  
  
-- core library function example: `type()`, `print()`  
local var = 'hello world'  
print(var)  
type(var)  

Parameters

  • (\Library) $library

Return Values

void


Luar::addLibrary

Description

public addLibrary (\Library $library)

Adds a library to the interpreter.

The functions will be added to a global table. The name of the table will match the name of the library.

Parameters

  • (\Library) $library

Return Values

void


Luar::assign

Description

public assign (string $name, mixed $value)

Injects a variable or function into the global scope.

Parameters

  • (string) $name : - Name of the variable
  • (mixed) $value : - variable or function to inject

Return Values

void


Luar::call

Description

public call (string $name, array $args)

Calls a function in the global scope.

Parameters

  • (string) $name : - name of the function
  • (array) $args : - arguments to be passed to the function

Return Values

mixed

Throws Exceptions

\LuarException

  • thrown if the name does not resolve to a global function

Luar::callLuarClosure

Description

public callLuarClosure (callable $closure, array $args)

Calls a closure generated by Luar.

Might be useful, for example, if you define the function myCustomFunction which takes an argument a function, which you need to call inside the function handler.

myCustomFunction(function (in)  
  local out  
  -- do something...  
  return out  
end)  

Parameters

  • (callable) $closure
  • (array) $args

Return Values

mixed


Luar::eval

Description

public eval (string $program)

Evaluates a Lua program.

Parameters

  • (string) $program

Return Values

mixed


Luar::getGlobals

Description

public getGlobals (void)

Returns all the variables in the global scope as an array.

The names of the variables will be the keys of the array.

Parameters

This function has no parameters.

Return Values

array


Luar::packLuarObject

Description

public static packLuarObject (mixed $value)

Converts any PHP object to a LuarObject

Parameters

  • (mixed) $value

Return Values

\LuarObject


Luar::unpackLuarObject

Description

public static unpackLuarObject (\LuarObject $object)

Converts a LuarObject to a PHP object

Parameters

  • (\LuarObject) $object

Return Values

mixed