org.luaj.vm2.lib.jse
Class JseMathLib

java.lang.Object
  extended by org.luaj.vm2.lib.MathLib
      extended by org.luaj.vm2.lib.jse.JseMathLib

public class JseMathLib
extends org.luaj.vm2.lib.MathLib

Subclass of LibFunction which implements the lua standard math library.

It contains all lua math functions, including those not available on the JME platform. See org.luaj.vm2.lib.MathLib for the exception list.

Typically, this library is included as part of a call to JsePlatform.standardGlobals()

 Globals globals = JsePlatform.standardGlobals();
 System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
  

For special cases where the smallest possible footprint is desired, a minimal set of libraries could be loaded directly via LuaValue.load(LuaValue) using code such as:

 Globals globals = new Globals();
 globals.load(new JseBaseLib());
 globals.load(new PackageLib());
 globals.load(new JseMathLib());
 System.out.println( globals.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
  

However, other libraries such as CoroutineLib are not loaded in this case.

This has been implemented to match as closely as possible the behavior in the corresponding library in C.

See Also:
LibFunction, JsePlatform, org.luaj.vm2.lib.jme.JmePlatform, JseMathLib, Lua 5.2 Math Lib Reference

Constructor Summary
JseMathLib()
           
 
Method Summary
 LuaValue call(LuaValue modname, LuaValue env)
          Perform one-time initialization on the library by creating a table containing the library functions, adding that table to the supplied environment, adding the table to package.loaded, and returning table as the return value.
 double dpow_lib(double a, double b)
          Faster, better version of pow() used by arithmetic operator ^
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JseMathLib

public JseMathLib()
Method Detail

call

public LuaValue call(LuaValue modname,
                     LuaValue env)
Perform one-time initialization on the library by creating a table containing the library functions, adding that table to the supplied environment, adding the table to package.loaded, and returning table as the return value.

Specifically, adds all library functions that can be implemented directly in JSE but not JME: acos, asin, atan, atan2, cosh, exp, log, pow, sinh, and tanh.

Parameters:
modname - the module name supplied if this is loaded via 'require'.
env - the environment to load into, which must be a Globals instance.

dpow_lib

public double dpow_lib(double a,
                       double b)
Faster, better version of pow() used by arithmetic operator ^



Copyright © 2007-2015 Luaj.org. All Rights Reserved.