Class LibImpl
- java.lang.Object
-
- ca.cgjennings.apps.arkham.plugins.LibImpl
-
public final class LibImpl extends java.lang.Object
Helper methods that support the implementation of the script library.- Since:
- 3
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LibImpl.ScriptTraceElement
Information about a single frame on the script call stack.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LibImpl.ScriptTraceElement[]
getScriptTrace()
Return an array ofLibImpl.ScriptTraceElement
s that represents the script stack frames for the current thread.static java.lang.String
joinModulePath(java.lang.String path, java.lang.String child)
Given a path and a child path, return the child path resolved against the parent path.static java.lang.Object
require(java.lang.String requireSourcePath, java.lang.String modulePath, org.mozilla.javascript.Scriptable module, org.mozilla.javascript.Scriptable exports, org.mozilla.javascript.Scriptable cache)
Implements CommonJS require() support.static java.lang.String
sprintf(java.util.Locale loc, java.lang.String format, java.lang.Object... args)
Formats a string using C-style % format codes.
-
-
-
Method Detail
-
sprintf
public static java.lang.String sprintf(java.util.Locale loc, java.lang.String format, java.lang.Object... args)
Formats a string using C-style % format codes. The result is nearly identical toString.format
but it is more lenient about which format specifiers will accept which types.In particular, numeric format codes accept any type of number. If a floating point type is passed to an integer format specifier, or vice-versa, it will be converted to the appropriate type rather than throwing an error.
- Parameters:
loc
- The locale to apply during formatting. If null then no localization is applied.format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java™ Virtual Machine Specification.- Returns:
- the formatted string
-
require
public static java.lang.Object require(java.lang.String requireSourcePath, java.lang.String modulePath, org.mozilla.javascript.Scriptable module, org.mozilla.javascript.Scriptable exports, org.mozilla.javascript.Scriptable cache) throws java.io.IOException
Implements CommonJS require() support.- Parameters:
requireSourcePath
- the path to the script that is calling require, to resolve against a relative module pathmodulePath
- the relative module path to loadmodule
- the module object to pass to the moduleexports
- the module.exports object to pass to the module- Throws:
java.io.IOException
-
joinModulePath
public static java.lang.String joinModulePath(java.lang.String path, java.lang.String child)
Given a path and a child path, return the child path resolved against the parent path. The child path may be absolute, in which case it is returned unchanged. If the child path is relative, it is resolved against the parent path.- Parameters:
path
- the parent pathchild
- the child path- Returns:
- the combined path
-
getScriptTrace
public static LibImpl.ScriptTraceElement[] getScriptTrace()
Return an array ofLibImpl.ScriptTraceElement
s that represents the script stack frames for the current thread.- Returns:
- returns a script stack trace for the current thread
-
-