Add convenience function to load a String for execution.

This commit is contained in:
James Roseborough
2013-01-29 04:22:14 +00:00
parent cef619cb40
commit 1626aad303

View File

@@ -101,6 +101,17 @@ public class Globals extends LuaTable {
return !v.isnil(1)? v.arg1(): error(v.arg(2).tojstring()); return !v.isnil(1)? v.arg1(): error(v.arg(2).tojstring());
} }
/** Convenience function to load a string value as a script.
* @param script Contents of a lua script, such as "print 'hello, world.'"
* @param chunkname Name that will be used within the chunk as the source.
* @return LuaValue that may be executed via .call(), .invoke(), or .method() calls.
* @throws LuaError if the script could not be compiled.
*/
public LuaValue loadString(String script, String chunkname) {
Varargs v = baselib.loadStream(valueOf(script).toInputStream(), chunkname, "bt", this);
return !v.isnil(1)? v.arg1(): error(v.arg(2).tojstring());
}
/** Function which yields the current thread. /** Function which yields the current thread.
* @param args Arguments to supply as return values in the resume function of the resuming thread. * @param args Arguments to supply as return values in the resume function of the resuming thread.
* @return Values supplied as arguments to the resume() call that reactivates this thread. * @return Values supplied as arguments to the resume() call that reactivates this thread.