{"id":15069224,"url":"https://github.com/luaj/luaj","last_synced_at":"2025-05-16T14:04:51.917Z","repository":{"id":40462134,"uuid":"41489420","full_name":"luaj/luaj","owner":"luaj","description":"Lightweight, fast, Java-centric Lua interpreter written for JME and JSE, with string, table, package, math, io, os, debug, coroutine \u0026 luajava libraries, JSR-223 bindings, all metatags, weak tables and unique direct lua-to-java-bytecode compiling.","archived":false,"fork":false,"pushed_at":"2023-04-24T08:10:39.000Z","size":3537,"stargazers_count":954,"open_issues_count":71,"forks_count":181,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-12T10:59:39.986Z","etag":null,"topics":["java","jvm","lua","scripting","scripting-language"],"latest_commit_sha":null,"homepage":"http://luaj.sourceforge.net/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luaj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-27T13:51:27.000Z","updated_at":"2025-04-08T16:16:36.000Z","dependencies_parsed_at":"2024-10-13T03:41:35.058Z","dependency_job_id":"ffaf78cd-6f72-4356-9919-3c6b591ba3fb","html_url":"https://github.com/luaj/luaj","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luaj%2Fluaj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luaj%2Fluaj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luaj%2Fluaj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luaj%2Fluaj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luaj","download_url":"https://codeload.github.com/luaj/luaj/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jvm","lua","scripting","scripting-language"],"created_at":"2024-09-25T01:41:11.932Z","updated_at":"2025-05-16T14:04:51.899Z","avatar_url":"https://github.com/luaj.png","language":"Java","readme":"# This is a fork!\n\u003cdiv style=\"border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;\"\u003e\nThis repository has been forked from the original CVS sources of Luaj.\nThe commit history has been converted to make sure that the original work of\nJames Roseborough and Ian Farmer is not lost.\nUnfortunately, I was not able to contact either James or Ian to hand over\nownership of the Github organization/repo as I have originally intended to.\nThe community however seems interested enough to continue work on the original\nsources and therefore I have decided to make sure that any useful pull requests\nthat may add some value to the original code base shall be merged in from now\non.\u003cbr\u003e\n-- Benjamin P. Jung, Jan. 26th 2018\n\u003c/div\u003e\n\n\u003ch1\u003eGetting Started with LuaJ\u003c/h1\u003e\nJames Roseborough, Ian Farmer, Version 3.0.2\n\u003cp\u003e\n\u003csmall\u003e\nCopyright \u0026copy; 2009-2014 Luaj.org.\nFreely available under the terms of the\n\u003ca href=\"LICENSE\"\u003eLuaj license\u003c/a\u003e.\n\u003c/small\u003e\n\u003chr\u003e\n\u003cp\u003e\n\n\u003ca href=\"#1\"\u003eintroduction\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#2\"\u003eexamples\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#3\"\u003econcepts\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#4\"\u003elibraries\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#5\"\u003eluaj api\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#6\"\u003eparser\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#7\"\u003ebuilding\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#8\"\u003edownloads\u003c/a\u003e\n\u0026middot;\n\u003ca href=\"#9\"\u003erelease notes\u003c/a\u003e\n\n\u003c!-- ====================================================================== --\u003e\n\u003cp\u003e\n\n\u003ch1\u003e1 - \u003ca name=\"1\"\u003eIntroduction\u003c/a\u003e\u003c/h1\u003e\n\u003ch2\u003eGoals of Luaj\u003c/h2\u003e\nLuaj is a lua interpreter based on the 5.2.x version of lua with the following goals in mind:\n\u003cul\u003e\n\u003cli\u003eJava-centric implementation of lua vm built to leverage standard Java features.\n\u003cli\u003eLightweight, high performance execution of lua. \n\u003cli\u003eMulti-platform to be able to run on JME, JSE, or JEE environments. \n\u003cli\u003eComplete set of libraries and tools for integration into real-world projects.\n\u003cli\u003eDependable due to sufficient unit testing of vm and library features. \n\u003c/ul\u003e\n\n\u003ch2\u003eLuaj version and Lua Versions\u003c/h2\u003e\n\u003ch3\u003eLuaj 3.0.x\u003c/h3\u003e\nSupport for lua 5.2.x features:\n\u003cul\u003e\n\u003cli\u003e_ENV environments model.\n\u003cli\u003eyield from pcall or metatags.\n\u003cli\u003eBitwise operator library.\n\u003c/ul\u003e\nIt also includes miscellaneous improvements over luaj 2.0.x:\n\u003cul\u003e\n\u003cli\u003eBetter thread safety.\n\u003cli\u003eMore compatible table behavior.\n\u003cli\u003eBetter coroutine-related garbage collection. \n\u003cli\u003eMaven integration.\n\u003cli\u003eBetter debug reporting when using closures.\n\u003cli\u003eLine numbers in parse syntax tree.\n\u003c/ul\u003e\n\u003ch3\u003eLuaj 2.0.x\u003c/h3\u003e\nSupport for lua 5.1.x features, plus:\n\u003cul\u003e\n\u003cli\u003eSupport for compiling lua source code into Java source code.\n\u003cli\u003eSupport for compiling lua bytecode directly into Java bytecode.\n\u003cli\u003eStackless vm design centered around dynamically typed objects.\n\u003cli\u003eGood alignment with C API (see \u003ca href=\"names.csv\"\u003enames.csv\u003c/a\u003e for details)\n\u003cli\u003eImplementation of weak keys and values, and all metatags. \n\u003c/ul\u003e\n\u003ch3\u003eLuaj 1.0.x\u003c/h3\u003e\nSupport for most lua 5.1.x features.\n\n\u003ch2\u003ePerformance\u003c/h2\u003e\nGood performance is a major goal of luaj.  \nThe following table provides measured execution times on a subset of benchmarks from \n\u003ca href=\"http://shootout.alioth.debian.org/\"\u003ethe computer language benchmarks game\u003c/a\u003e  \nin comparison with the standard C distribution. \n\u003ctable cellspacing=\"10\"\u003e\u003ctr\u003e\u003ctd\u003e\u003ctable\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003e\u003cu\u003eProject\u003c/td\u003e\n\t\u003ctd\u003e\u003cu\u003eVersion\u003c/td\u003e\n\t\u003ctd\u003e\u003cu\u003eMode\u003c/td\u003e\n\t\u003ctd rowspan=\"9\"\u003e\u0026nbsp;\u0026nbsp;\u003c/td\u003e\n\t\u003ctd colspan=\"4\" align=\"center\"\u003e\u003cu\u003eBenchmark\u0026nbsp;execution\u0026nbsp;time\u0026nbsp;(sec)\u003c/td\u003e\n\t\u003ctd rowspan=\"9\"\u003e\u0026nbsp;\u0026nbsp;\u003c/td\u003e\n\t\u003ctd\u003e\u003cu\u003eLanguage\u003c/td\u003e\n\t\u003ctd\u003e\u003cu\u003eSample\u0026nbsp;command\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd colspan=\"2\"\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003cem\u003ebinarytrees 15\u003c/em\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003cem\u003efannkuch 10\u003c/em\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003cem\u003enbody 1e6\u003c/em\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003cem\u003ensieve 9\u003c/em\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003eluaj\u003c/td\u003e\n\t\u003ctd\u003e3.0\u003c/td\u003e\n\t\u003ctd\u003e-b (luajc)\u003c/td\u003e\n\t\u003ctd\u003e2.980\u003c/td\u003e\n\t\u003ctd\u003e5.073\u003c/td\u003e\n\t\u003ctd\u003e16.794\u003c/td\u003e\n\t\u003ctd\u003e11.274\u003c/td\u003e\n\t\u003ctd\u003eJava\u003c/td\u003e\n\t\u003ctd\u003ejava -cp luaj-jse-3.0.2.jar;bcel-5.2.jar lua \u003cb\u003e-b\u003c/b\u003e fannkuch.lua 10\u003c/td\u003e\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e-n (interpreted)\u003c/td\u003e\n\t\u003ctd\u003e12.838\u003c/td\u003e\n\t\u003ctd\u003e23.290\u003c/td\u003e\n\t\u003ctd\u003e36.894\u003c/td\u003e\n\t\u003ctd\u003e15.163\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003ejava -cp luaj-jse-3.0.2.jar lua -n fannkuch.lua 10\u003c/td\u003e\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003elua\u003c/td\u003e\n\t\u003ctd\u003e5.1.4\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e17.637\u003c/td\u003e\n\t\u003ctd\u003e16.044\u003c/td\u003e\n\t\u003ctd\u003e15.201\u003c/td\u003e\n\t\u003ctd\u003e5.477\u003c/td\u003e\n\t\u003ctd\u003eC\u003c/td\u003e\n\t\u003ctd\u003elua fannkuch.lua 10\u003c/td\u003e\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003ejill\u003c/td\u003e\n\t\u003ctd\u003e1.0.1\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e44.512\u003c/td\u003e\n\t\u003ctd\u003e54.630\u003c/td\u003e\n\t\u003ctd\u003e72.172\u003c/td\u003e\n\t\u003ctd\u003e20.779\u003c/td\u003e\n\t\u003ctd\u003eJava\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003ekahlua\u003c/td\u003e\n\t\u003ctd\u003e1.0\u003c/td\u003e\n\t\u003ctd\u003ejse\u003c/td\u003e\n\t\u003ctd\u003e22.963\u003c/td\u003e\n\t\u003ctd\u003e63.277\u003c/td\u003e\n\t\u003ctd\u003e68.223\u003c/td\u003e\n\t\u003ctd\u003e21.529\u003c/td\u003e\n\t\u003ctd\u003eJava\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr valign=\"top\"\u003e\n\t\u003ctd\u003emochalua\u003c/td\u003e\n\t\u003ctd\u003e1.0\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\n\t\u003ctd\u003e50.457\u003c/td\u003e\n\t\u003ctd\u003e70.368\u003c/td\u003e\n\t\u003ctd\u003e82.868\u003c/td\u003e\n\t\u003ctd\u003e41.262\u003c/td\u003e\n\t\u003ctd\u003eJava\u003c/td\u003e\n\t\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\nLuaj in interpreted mode performs well for the benchmarks, and even better when \nthe lua-to-java-bytecode (luajc) compiler is used, \nand actually executes \u003cem\u003efaster\u003c/em\u003e than C-based lua in some cases.  \nIt is also faster than Java-lua implementations Jill, Kahlua, and Mochalua for all benchmarks tested.  \n\n\u003ch1\u003e2 - \u003ca name=\"2\"\u003eExamples\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eRun a lua script in Java SE\u003c/h2\u003e\n\n\u003cp\u003e\nFrom the main distribution directory line type:\n\n\u003cpre\u003e\n\tjava -cp luaj-jse-3.0.2.jar lua examples/lua/hello.lua\n\u003c/pre\u003e\n\n\u003cp\u003e\nYou should see the following output:\n\u003cpre\u003e\n\thello, world\n\u003c/pre\u003e\n\nTo see how luaj can be used to acccess most Java API's including swing, try:\n\n\u003cpre\u003e\n\tjava -cp luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua\n\u003c/pre\u003e\n\n\u003cp\u003e\nLinks to sources:\u003cpre\u003e\n\t\u003ca href=\"examples/lua/hello.lua\"\u003eexamples/lua/hello.lua\u003c/a\u003e\n\t\u003ca href=\"examples/lua/swingapp.lua\"\u003eexamples/lua/swingapp.lua\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003ch2\u003eCompile lua source to lua bytecode\u003c/h2\u003e\n\n\u003cp\u003e\nFrom the main distribution directory line type:\n\n\u003cpre\u003e\n\tjava -cp luaj-jse-3.0.2.jar luac examples/lua/hello.lua\n\tjava -cp luaj-jse-3.0.2.jar lua luac.out\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe compiled output \"luac.out\" is lua bytecode and should run and produce the same result.\n\n\n\u003ch2\u003eCompile lua source or bytecode to java bytecode\u003c/h2\u003e\n\n\u003cp\u003e\nLuaj can compile lua sources or binaries directly to java bytecode if the bcel library is on the class path. From the main distribution directory line type:\n\n\u003cpre\u003e\n\tant bcel-lib\n\tjava -cp \u0026quot;luaj-jse-3.0.2.jar;lib/bcel-5.2.jar\u0026quot; luajc -s examples/lua -d . hello.lua\n\tjava -cp \u0026quot;luaj-jse-3.0.2.jar;.\u0026quot; lua -l hello\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe output \u003cem\u003ehello.class\u003c/em\u003e is Java bytecode, should run and produce the same result.\nThere is no runtime dependency on the bcel library, \nbut the compiled classes must be in the class path at runtime, unless runtime jit-compiling via luajc and bcel are desired (see later sections).\n\n\u003cp\u003e\nLua scripts can also be run directly in this mode without precompiling using the \u003cem\u003elua\u003c/em\u003e command with the \u003cb\u003e\u003cem\u003e-b\u003c/em\u003e\u003c/b\u003e option and providing the \u003cem\u003ebcel\u003c/em\u003e library in the class path:\n\u003cpre\u003e\n\tjava -cp \u0026quot;luaj-jse-3.0.2.jar;lib/bcel-5.2.jar\u0026quot; lua -b examples/lua/hello.lua\n\u003c/pre\u003e\n\n\n\u003ch2\u003eRun a script in a Java Application\u003c/h2\u003e\n\n\u003cp\u003e\nA simple hello, world example in luaj is:\n\n\u003cpre\u003e\n\timport org.luaj.vm2.*;\n\timport org.luaj.vm2.lib.jse.*;\n\n\tGlobals globals = JsePlatform.standardGlobals();\n\tLuaValue chunk = globals.load(\"print 'hello, world'\");\n\tchunk.call();\n\t\n\u003c/pre\u003e\n\nLoading from a file is done via Globals.loadFile():\n\n\u003cpre\u003e\n\tLuaValue chunk = globals.loadfile(\"examples/lua/hello.lua\");\n\u003c/pre\u003e\n\nChunks can also be loaded from a \u003ccode\u003eReader\u003c/code\u003e as text source\n\n\u003cpre\u003e\n\tchunk = globals.load(new StringReader(\"print 'hello, world'\"), \"main.lua\");\n\u003c/pre\u003e\n\nor an InputStream to be loaded as text source \"t\", or binary lua file \"b\":\n\n\u003cpre\u003e\n\tchunk = globals.load(new FileInputSStream(\"examples/lua/hello.lua\"), \"main.lua\", \"bt\"));\n\u003c/pre\u003e\n\n\u003cp\u003e\nA simple example may be found in\n\u003cpre\u003e\n\t\u003ca href=\"examples/jse/SampleJseMain.java\"\u003eexamples/jse/SampleJseMain.java\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nYou must include the library \u003cb\u003eluaj-jse-3.0.2.jar\u003c/b\u003e in your class path.\n\n\u003ch2\u003eRun a script in a MIDlet\u003c/h2\u003e\n\n\u003cp\u003e\nFor MIDlets the \u003cem\u003eJmePlatform\u003c/em\u003e is used instead:\n\n\u003cpre\u003e\n\timport org.luaj.vm2.*;\n\timport org.luaj.vm2.lib.jme.*;\n\n\tGlobals globals = JmePlatform.standardGlobals();\n\tLuaValue chunk = globals.loadfile(\"examples/lua/hello.lua\");\n\tchunk.call();\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe file must be a resource within within the midlet jar for the loader to find it.\nAny files included via \u003cem\u003erequire()\u003c/em\u003e must also be part of the midlet resources.\n\n\u003cp\u003e\nA simple example may be found in\n\u003cpre\u003e\n\t\u003ca href=\"examples/jme/SampleMIDlet.java\"\u003eexamples/jme/SampleMIDlet.java\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nYou must include the library \u003cb\u003eluaj-jme-3.0.2.jar\u003c/b\u003e in your midlet jar.\n\n\u003cp\u003e\nAn ant script to build and run the midlet is in\n\u003cpre\u003e\n\t\u003ca href=\"build-midlet.xml\"\u003ebuild-midlet.xml\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nYou must install the wireless toolkit and define \u003cem\u003eWTK_HOME\u003c/em\u003e for this script to work. \n\n\u003ch2\u003eRun a script using JSR-223 Dynamic Scripting\u003c/h2\u003e\n\n\u003cp\u003e\nThe standard use of JSR-223 scripting engines may be used:\n\n\u003cpre\u003e\n\tScriptEngineManager mgr = new ScriptEngineManager();\n\tScriptEngine e = mgr.getEngineByName(\"luaj\");\n\te.put(\"x\", 25);\n\te.eval(\"y = math.sqrt(x)\");\n\tSystem.out.println( \"y=\"+e.get(\"y\") );\n\u003c/pre\u003e\n\nYou can also look up the engine by language \"lua\" or mimetypes \"text/lua\" or \"application/lua\".\n\n\u003cp\u003e\nAll standard aspects of script engines including compiled statements are supported.\n\n\u003cp\u003e\nYou must include the library \u003cb\u003eluaj-jse-3.0.2.jar\u003c/b\u003e in your class path.\n\n\u003cp\u003e\nA working example may be found in\n\u003cpre\u003e\n\t\u003ca href=\"examples/jse/ScriptEngineSample.java\"\u003eexamples/jse/ScriptEngineSample.java\u003c/a\u003e\n\u003c/pre\u003e\n\nTo compile and run it using Java 1.6 or higher:\n\n\u003cpre\u003e\n\tjavac -cp luaj-jse-3.0.2.jar examples/jse/ScriptEngineSample.java\n\tjava -cp \u0026quot;luaj-jse-3.0.2.jar;examples/jse\u0026quot; ScriptEngineSample\n\u003c/pre\u003e\n\n\u003ch2\u003eExcluding the lua bytecode compiler\u003c/h2\u003e\n\nBy default, the compiler is included whenever \u003cem\u003estandardGlobals()\u003c/em\u003e or \u003cem\u003edebugGlobals()\u003c/em\u003e are called.  \nWithout a compiler, files can still be executed, but they must be compiled elsewhere beforehand.\nThe \"luac\" utility is provided in the jse jar for this purpose, or a standard lua compiler can be used.  \n\n\u003cp\u003e\nTo exclude the lua-to-lua-bytecode compiler, do not call \n\u003cem\u003estandardGlobals()\u003c/em\u003e or \u003cem\u003edebugGlobals()\u003c/em\u003e \nbut instead initialize globals with including only those libraries \nthat are needed and omitting the line:\n\u003cpre\u003e\n\torg.luaj.vm2.compiler.LuaC.install(globals);\n\u003c/pre\u003e\n\n\n\u003ch2\u003eIncluding the LuaJC lua-bytecode-to-Java-bytecode compiler\u003c/h2\u003e\n\n\u003cp\u003e\nTo compile from lua to Java bytecode for all lua loaded at runtime, \ninstall the LuaJC compiler into a \u003cem\u003eglobals\u003c/em\u003e object use:\n\n\u003cpre\u003e\n\torg.luaj.vm2.jse.luajc.LuaJC.install(globals);\n\u003c/pre\u003e\n\n\u003cp\u003e\nThis will compile all lua bytecode into Java bytecode, regardless of if they are loaded as\nlua source or lua binary files.\n\n\u003cp\u003e\nThe requires \u003cem\u003ebcel\u003c/em\u003e to be on the class path, and the ClassLoader of JSE or CDC.  \n\n\u003ch1\u003e3 - \u003ca name=\"3\"\u003eConcepts\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eGlobals\u003c/h2\u003e\nThe old notion of platform has been replaced with creation of globals.  \nThe  \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/Globals.html\"\u003eGlobals\u003c/a\u003e\nclass holds global state needed for executing closures as well as providing \nconvenience functions for compiling and loading scripts.\n\n\u003ch2\u003ePlatform\u003c/h2\u003e\nTo simplify construction of Globals, and encapsulate differences needed to support \nthe diverse family of Java runtimes, luaj uses a Platform notion.  \nTypically, a platform is used to construct a Globals, which is then provided as a global \nenvironment for client scripts.\n\n\u003ch3\u003eJsePlatform\u003c/h3\u003e\nThe \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/jse/JsePlatform.html\"\u003eJsePlatform\u003c/a\u003e \nclass can be used as a factory for globals in a typical Java SE application. \nAll standard libraries are included, as well as the luajava library. \nThe default search path is the current directory,\nand the math operations include all those supported by Java SE.\n\n\u003ch4\u003eAndroid\u003c/h4\u003e\n\nAndroid applications should use the JsePlatform, and can include the \u003ca href=\"#luajava\"\u003eLuajava\u003c/a\u003e library \nto simplify access to underlying Android APIs.  \nA specialized Globals.finder should be provided to find scripts and data for loading.\nSee \u003ca href=\"examples/android/src/android/LuajView.java\"\u003eexamples/android/src/android/LuajView.java\u003c/a\u003e\nfor an example that loads from the \"res\" Android project directory.\nThe ant build script is \u003ca href=\"examples/android/build.xml\"\u003eexamples/android/build.xml\u003c/a\u003e.  \n\n\u003ch4\u003eApplet\u003c/h4\u003e\n\nApplets in browsers should use the JsePlatform.  The permissions model in applets is \nhighly restrictive, so a specialization of the \u003ca href=\"#luajava\"\u003eLuajava\u003c/a\u003e library must be used that \nuses default class loading.  This is illustrated in the sample Applet \n\u003ca href=\"examples/jse/SampleApplet.java\"\u003eexamples/jse/SampleApplet.java\u003c/a\u003e, \nwhich can be built using \u003ca href=\"build-applet.xml\"\u003ebuild-applet.xml\u003c/a\u003e.\n\n\n\u003ch3\u003eJmePlatform\u003c/h3\u003e\nThe \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/jme/JmePlatform.html\"\u003eJmePlatform\u003c/a\u003e \nclass can be used to set up the basic environment for a Java ME application.\nThe default search path is limited to the jar resources,\nand the math operations are limited to those supported by Java ME.\nAll libraries are included except luajava, and the os, io, and math libraries are \nlimited to those functions that can be supported on that platform.\n\n\u003ch4\u003eMIDlet\u003c/h4\u003e\n\nMIDlets require the JmePlatform.  \nThe JME platform has several limitations which carry over to luaj.\nIn particular Globals.finder is overridden to load as resources, so scripts should be \ncolocated with class files in the MIDlet jar file.  \u003ca href=\"#luajava\"\u003eLuajava\u003c/a\u003e cannot be used.\nCamples code is in  \n\u003ca href=\"examples/jme/SampleMIDlet.java\"\u003eexamples/jme/SampleMIDlet.java\u003c/a\u003e, \nwhich can be built using \u003ca href=\"build-midlet.xml\"\u003ebuild-midlet.xml\u003c/a\u003e.\n\n\n\u003ch2\u003eThread Safety\u003c/h2\u003e\n\nLuaj 3.0 can be run in multiple threads, with the following restrictions:\n\u003cul\u003e\n\u003cli\u003eEach thread created by client code must be given its own, distinct Globals instance\n\u003cli\u003eEach thread must not be allowed to access Globals from other threads\n\u003cli\u003eMetatables for Number, String, Thread, Function, Boolean, and and Nil \n are shared and therefore should not be mutated once lua code is running in any thread.\n\u003c/ul\u003e\n\nFor an example of loading allocating per-thread Globals and invoking scripts in \nmultiple threads see \u003ca href=\"examples/jse/SampleMultiThreaded.java\"\u003eexamples/jse/SampleMultiThreaded.java\u003c/a\u003e\n\n\u003cp\u003e\nAs an alternative, the JSR-223 scripting interface can be used, and should always provide a separate Globals instance \nper script engine instance by using a ThreadLocal internally.  \n\n\u003ch2\u003eSandboxing\u003c/h2\u003e\nLua and luaj are allow for easy sandboxing of scripts in a server environment.\n\u003cP\u003e\nConsiderations include\n\u003cul\u003e\n\u003cli\u003eThe \u003cem\u003edebug\u003c/em\u003e and \u003cem\u003eluajava\u003c/em\u003e library give unfettered access to the luaj vm and java vm so can be abused\n\u003cli\u003ePortions of the \u003cem\u003eos\u003c/em\u003e, \u003cem\u003eio\u003c/em\u003e, and \u003cem\u003ecoroutine\u003c/em\u003e libraries are prone to abuse \n\u003cli\u003eRogue scripts may need to be throttled or killed\n\u003cli\u003eShared metatables (string, booleans, etc.) need to be made read-only or isolated via class loaders\nsuch as \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/server/LuajClassLoader.html\"\u003eLuajClassLoader\u003c/a\u003e\n\u003c/ul\u003e\n\nLuaj provides sample code covering various approaches:\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"examples/jse/SampleSandboxed.java\"\u003eexamples/jse/SampleSandboxed.java\u003c/a\u003e\nA java sandbox that limits libraries, limits bytecodes per script, and makes shared tables read-only\n\u003cli\u003e\u003ca href=\"examples/lua/samplesandboxed.lua\"\u003eexamples/jse/samplesandboxed.lua\u003c/a\u003e\nA lua sandbox that limits librares,limits bytecodes per script, and makes shared tables read-only\n\u003cli\u003e\u003ca href=\"examples/jse/SampleUsingClassLoader.java\"\u003eexamples/jse/SampleUsingClassLoader.java\u003c/a\u003e\nA heavier but strong sandbox where each script gets its own class loader and a full private luaj implementation\n\u003c/ul\u003e\n\n\u003ch1\u003e4 - \u003ca name=\"4\"\u003eLibraries\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eStandard Libraries\u003c/h2\u003e\n\nLibraries are coded to closely match the behavior specified in \nSee \u003ca href=\"http://www.lua.org/manual/5.1/\"\u003estandard lua documentation\u003c/a\u003e for details on the library API's\n\n\u003cp\u003e\nThe following libraries are loaded by both \u003cem\u003eJsePlatform.standardGlobals()\u003c/em\u003e and \u003cem\u003eJmePlatform.standardGlobals()\u003c/em\u003e:\n\u003cpre\u003e\tbase\n\tbit32\n\tcoroutine\n\tio\n\tmath\n\tos\n\tpackage\n\tstring\n\ttable\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe \u003cem\u003eJsePlatform.standardGlobals()\u003c/em\u003e globals also include:\n\u003cpre\u003e\tluajava \n\u003c/pre\u003e\n\n\u003cp\u003e\nThe \u003cem\u003eJsePlatform.debugGlobals()\u003c/em\u003e and \u003cem\u003eJsePlatform.debugGlobals()\u003c/em\u003e functions produce globals that include:\n\u003cpre\u003e\tdebug\n\u003c/pre\u003e\n\n\u003ch3\u003eI/O Library\u003c/h3\u003e\nThe implementation of the \u003cem\u003eio\u003c/em\u003e library differs by platform owing to platform limitations.\n\n\u003cp\u003e\nThe \u003cem\u003eJmePlatform.standardGlobals()\u003c/em\u003e instantiated the io library \u003cem\u003eio\u003c/em\u003e in \n\u003cpre\u003e\n\tsrc/jme/org/luaj/vm2/lib/jme/JmeIoLib.java\n\u003c/pre\u003e\n\nThe \u003cem\u003eJsePlatform.standardGlobals()\u003c/em\u003e includes support for random access and is in \n\u003cpre\u003e\n\tsrc/jse/org/luaj/vm2/lib/jse/JseIoLib.java\n\u003c/pre\u003e\n\n\u003ch3\u003eOS Library\u003c/h3\u003e\nThe implementation of the \u003cem\u003eos\u003c/em\u003e library also differs per platform.\n\n\u003cp\u003e\nThe basic \u003cem\u003eos\u003c/em\u003e library implementation us used by \u003cem\u003eJmePlatform\u003c/em\u003e and is in:\n\u003cpre\u003e\n\tsrc/core/org/luaj/lib/OsLib.java\n\u003c/pre\u003e\n\nA richer version for use by \u003cem\u003eJsePlatform\u003c/em\u003e is : \n\u003cpre\u003e\n\tsrc/jse/org/luaj/vm2/lib/jse/JseOsLib.java\n\u003c/pre\u003e\n\nTime is a represented as number of seconds since the epoch, \nand locales are not implemented.\n\n\u003ch3\u003eCoroutine Library\u003c/h3\u003e\nThe \u003cem\u003ecoroutine\u003c/em\u003e library is implemented using one JavaThread per coroutine.   \nThis allows \u003cem\u003ecoroutine.yield()\u003c/em\u003e can be called from anywhere, \nas with the yield-from-anywhere patch in C-based lua. \n\n\u003cp\u003e\nLuaj uses WeakReferences and the OrphanedThread error to ensure that coroutines that are no longer referenced \nare properly garbage collected.  For thread safety, OrphanedThread should not be caught by Java code.  \nSee \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaThread.html\"\u003eLuaThread\u003c/a\u003e\nand \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/OrphanedThread.html\"\u003eOrphanedThread\u003c/a\u003e\njavadoc for details.  The sample code in \u003ca href=\"examples/jse/CollectingOrphanedCoroutines.java\"\u003eexamples/jse/CollectingOrphanedCoroutines.java\u003c/a\u003e\nprovides working examples.\n\n\u003ch3\u003eDebug Library\u003c/h3\u003e\nThe \u003cem\u003edebug\u003c/em\u003e library is not included by default by \n\u003cem\u003eJmePlatform.standardGlobals()\u003c/em\u003e or \u003cem\u003eJsePlatform.standardGlobsls()\u003c/em\u003e .\n\nThe functions \u003cem\u003eJmePlatform.debugGlobals()\u003c/em\u003e and \u003cem\u003eJsePlatform.debugGlobsls()\u003c/em\u003e \ncreate globals that contain the debug library in addition to the other standard libraries. \n\nTo install dynamically from lua use java-class-based require:\u003c/em\u003e:\n\u003cpre\u003e\n\trequire 'org.luaj.vm2.lib.DebugLib'\n\u003c/pre\u003e\n\nThe \u003cem\u003elua\u003c/em\u003e command line utility includes the \u003cem\u003edebug\u003c/em\u003e library by default.\n\n\n\u003ch3\u003e\u003ca name=\"luajava\"\u003eThe Luajava Library\u003c/a\u003e\u003c/h3\u003e\nThe \u003cem\u003eJsePlatform.standardGlobals()\u003c/em\u003e includes the \u003cem\u003eluajava\u003c/em\u003e library, which simplifies binding to Java classes and methods.  \nIt is patterned after the original \u003ca href=\"http://www.keplerproject.org/luajava/\"\u003eluajava project\u003c/a\u003e.\n\n\u003cp\u003e\nThe following lua script will open a swing frame on Java SE:\n\u003cpre\u003e\n\tjframe = luajava.bindClass( \"javax.swing.JFrame\" )\n\tframe = luajava.newInstance( \"javax.swing.JFrame\", \"Texts\" );\n\tframe:setDefaultCloseOperation(jframe.EXIT_ON_CLOSE)\n\tframe:setSize(300,400)\n\tframe:setVisible(true)\n\u003c/pre\u003e\n\n\u003cp\u003e\nSee a longer sample in \u003cem\u003eexamples/lua/swingapp.lua\u003c/em\u003e for details, including a simple animation loop, rendering graphics, mouse and key handling, and image loading. \nOr try running it using: \n\u003cpre\u003e\n\tjava -cp luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua\n\u003c/pre\u003e\n\n\u003cp\u003e\nThe Java ME platform does not include this library, and it cannot be made to work because of the lack of a reflection API in Java ME. \n\n\u003cp\u003e\nThe \u003cem\u003elua\u003c/em\u003e connand line tool includes \u003cem\u003eluajava\u003c/em\u003e. \n\n\u003ch1\u003e5 - \u003ca name=\"5\"\u003eLuaJ API\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eAPI Javadoc\u003c/h2\u003e\nThe javadoc for the main classes in the LuaJ API are on line at\n\u003cpre\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/index.html\"\u003ehttp://luaj.org/luaj/3.0/api\u003c/a\u003e\n\u003c/pre\u003e\n\nYou can also build a local version from sources using \n\u003cpre\u003e\n\t ant doc\n\u003c/pre\u003e\n\n\u003ch2\u003eLuaValue and Varargs\u003c/h2\u003e\nAll lua value manipulation is now organized around \n\u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaValue.html\"\u003eLuaValue\u003c/a\u003e\nwhich exposes the majority of interfaces used for lua computation.  \n\u003cpre\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaValue.html\"\u003eorg.luaj.vm2.LuaValue\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003ch3\u003eCommon Functions\u003c/h3\u003e\n\u003cem\u003eLuaValue\u003c/em\u003e exposes functions for each of the operations in LuaJ.  \nSome commonly used functions and constants include:\n\u003cpre\u003e\n\tcall();               // invoke the function with no arguments\n\tcall(LuaValue arg1);  // call the function with 1 argument\n\tinvoke(Varargs arg);  // call the function with variable arguments, variable return values\n\tget(int index);       // get a table entry using an integer key\n\tget(LuaValue key);    // get a table entry using an arbitrary key, may be a LuaInteger\n\trawget(int index);    // raw get without metatable calls\n\tvalueOf(int i);       // return LuaValue corresponding to an integer\n\tvalueOf(String s);    // return LuaValue corresponding to a String\n\ttoint();              // return value as a Java int\n\ttojstring();          // return value as a Java String\n\tisnil();              // is the value nil\n\tNIL;                  // the value nil\n\tNONE;                 // a Varargs instance with no values\t \n\u003c/pre\u003e\n\n\u003ch2\u003eVarargs\u003c/h2\u003e\nThe interface \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/Varargs.html\"\u003eVarargs\u003c/a\u003e provides an abstraction for \nboth a variable argument list and multiple return values.  \nFor convenience, \u003cem\u003eLuaValue\u003c/em\u003e implements \u003cem\u003eVarargs\u003c/em\u003e so a single value can be supplied anywhere \nvariable arguments are expected.      \n\u003cpre\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/Varargs.html\"\u003eorg.luaj.vm2.Varargs\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003ch3\u003eCommon Functions\u003c/h3\u003e\n\u003cem\u003eVarargs\u003c/em\u003e exposes functions for accessing elements, and coercing them to specific types:\n\u003cpre\u003e\n\tnarg();                 // return number of arguments\n\targ1();                 // return the first argument\n\targ(int n);             // return the nth argument\n\tisnil(int n);           // true if the nth argument is nil\n\tchecktable(int n);      // return table or throw error\n\toptlong(int n,long d);  // return n if a long, d if no argument, or error if not a long\n\u003c/pre\u003e\n \nSee the \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/Varargs.html\"\u003eVarargs\u003c/a\u003e API for a complete list.\n \n\u003ch2\u003eLibFunction\u003c/h2\u003e\nThe simplest way to implement a function is to choose a base class based on the number of arguments to the function.\nLuaJ provides 5 base classes for this purpose, depending if the function has 0, 1, 2, 3 or variable arguments, \nand if it provide multiple return values.   \n\u003cpre\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ZeroArgFunction.html\"\u003eorg.luaj.vm2.lib.ZeroArgFunction\u003c/a\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/OneArgFunction.html\"\u003eorg.luaj.vm2.lib.OneArgFunction\u003c/a\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/TwoArgFunction.html\"\u003eorg.luaj.vm2.lib.TwoArgFunction\u003c/a\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ThreeArgFunction.html\"\u003eorg.luaj.vm2.lib.ThreeArgFunction\u003c/a\u003e\n\t \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/VarArgFunction.html\"\u003eorg.luaj.vm2.lib.VarArgFunction\u003c/a\u003e\n\u003c/pre\u003e\n\nEach of these functions has an abstract method that must be implemented, \nand argument fixup is done automatically by the classes as each Java function is invoked.\n\n\u003cp\u003e\nAn example of a function with no arguments but a useful return value might be:\n\u003cpre\u003e\n\tpubic class hostname extends ZeroArgFunction {\n\t\tpublic LuaValue call() {\n\t\t\treturn valueOf(java.net.InetAddress.getLocalHost().getHostName());\n\t\t}\n\t}\n\u003c/pre\u003e\n\nThe value \u003cem\u003eenv\u003c/em\u003e is the environment of the function, and is normally supplied \nby the instantiating object whenever default loading is used. \n\n\u003cp\u003e\nCalling this function from lua could be done by:\n\u003cpre\u003e \n\tlocal hostname = require( 'hostname' )\n\u003c/pre\u003e\n\nwhile calling this function from Java would look like:\n\u003cpre\u003e \n\tnew hostname().call();\n\u003c/pre\u003e\n\nNote that in both the lua and Java case, extra arguments will be ignored, and the function will be called.  \nAlso, no virtual machine instance is necessary to call the function. \nTo allow for arguments, or return multiple values, extend one of the other base classes. \n\n\u003ch2\u003eLibraries of Java Functions\u003c/h2\u003e\nWhen require() is called, it will first attempt to load the module as a Java class that implements LuaFunction.  \nTo succeed, the following requirements must be met:\n\u003cul\u003e\n\u003cli\u003eThe class must be on the class path with name, \u003cem\u003emodname\u003c/em\u003e.\u003c/li\u003e\n\u003cli\u003eThe class must have a public default constructor.\u003c/li\u003e\n\u003cli\u003eThe class must inherit from LuaFunction.\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cp\u003e\nIf luaj can find a class that meets these critera, it will instantiate it, cast it to \u003cem\u003eLuaFunction\u003c/em\u003e \nthen call() the instance with two arguments: \nthe \u003cem\u003emodname\u003c/em\u003e used in the call to require(), and the environment for that function.  \nThe Java may use these values however it wishes. A typical case is to create named functions \nin the environment that can be called from lua. \n\n\u003cp\u003e\nA complete example of Java code for a simple toy library is in \u003ca href=\"examples/jse/hyperbolic.java\"\u003eexamples/jse/hyperbolic.java\u003c/a\u003e \n\u003cpre\u003e\nimport org.luaj.vm2.LuaValue;\nimport org.luaj.vm2.lib.*;\n\npublic class hyperbolic extends TwoArgFunction {\n\n\tpublic hyperbolic() {}\n\n\tpublic LuaValue call(LuaValue modname, LuaValue env) {\n\t\tLuaValue library = tableOf();\n\t\tlibrary.set( \"sinh\", new sinh() );\n\t\tlibrary.set( \"cosh\", new cosh() );\n\t\tenv.set( \"hyperbolic\", library );\n\t\treturn library;\n\t}\n\n\tstatic class sinh extends OneArgFunction {\n\t\tpublic LuaValue call(LuaValue x) {\n\t\t\treturn LuaValue.valueOf(Math.sinh(x.checkdouble()));\n\t\t}\n\t}\n\t\n\tstatic class cosh extends OneArgFunction {\n\t\tpublic LuaValue call(LuaValue x) {\n\t\t\treturn LuaValue.valueOf(Math.cosh(x.checkdouble()));\n\t\t}\n\t}\n}\n\u003c/pre\u003e\n\nIn this case the call to require invokes the library itself to initialize it.  The library implementation \nputs entries into a table, and stores this table in the environment.\n\n\u003cp\u003e\nThe lua script used to load and test it is in \u003ca href=\"examples/lua/hyperbolicapp.lua\"\u003eexamples/lua/hyperbolicapp.lua\u003c/a\u003e\n\u003cpre\u003e\n\trequire 'hyperbolic'\n\n\tprint('hyperbolic', hyperbolic)\n\tprint('hyperbolic.sinh', hyperbolic.sinh)\n\tprint('hyperbolic.cosh', hyperbolic.cosh)\n\n\tprint('sinh(0.5)', hyperbolic.sinh(0.5))\n\tprint('cosh(0.5)', hyperbolic.cosh(0.5))\n\u003c/pre\u003e\n\nFor this example to work the code in \u003cem\u003ehyperbolic.java\u003c/em\u003e must be compiled and put on the class path.\n \n\u003ch2\u003eClosures\u003c/h2\u003e\nClosures still exist in this framework, but are optional, and are only used to implement lua bytecode execution, \nand is generally not directly manipulated by the user of luaj.\n\u003cp\u003e\nSee the \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaClosure.html\"\u003eorg.luaj.vm2.LuaClosure\u003c/a\u003e \njavadoc for details on using that class directly. \n\n\u003ch1\u003e6 - \u003ca name=\"6\"\u003eParser\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eJavacc Grammar\u003c/h2\u003e\nA Javacc grammar was developed to simplify the creation of Java-based parsers for the lua language.\nThe grammar is specified for \u003ca href=\"https://javacc.dev.java.net/\"\u003ejavacc version 5.0\u003c/a\u003e because that tool generates standalone \nparsers that do not require a separate runtime.     \n\n\u003cp\u003e\nA plain undecorated grammer that can be used for validation is available in \n\u003ca href=\"http://luaj.org/luaj/3.0/grammar/Lua52.jj\"\u003egrammar/Lua52.jj\u003c/a\u003e\nwhile a grammar that generates a typed parse tree is in \n\u003ca href=\"http://luaj.org/luaj/3.0/grammar/LuaParser.jj\"\u003egrammar/LuaParser.jj\u003c/a\u003e\n\n\u003ch2\u003eCreating a Parse Tree from Lua Source\u003c/h2\u003e\nThe default lu compiler does a single-pass compile of lua source to lua bytecode, so no explicit parse tree is produced.  \n\n\u003cp\u003e\nTo simplify the creation of abstract syntax trees from lua sources, the LuaParser class is generated as part of the JME build.  \nTo use it, provide an input stream, and invoke the root generator, which will return a Chunk if the file is valid, \nor throw a ParseException if there is a syntax error.\n\n\u003cp\u003e\nFor example, to parse a file and print all variable names, use code like:\n\u003cpre\u003e\n\ttry {\n\t\tString file = \"main.lua\";\n\t\tLuaParser parser = new LuaParser(new FileInputStream(file));\n\t\tChunk chunk = parser.Chunk();\n\t\tchunk.accept( new Visitor() {\n\t\t\tpublic void visit(Exp.NameExp exp) {\n\t\t\t\tSystem.out.println(\"Name in use: \"+exp.name.name\n\t\t\t\t\t+\" line \"+exp.beginLine\n\t\t\t\t\t+\" col \"+exp.beginColumn);\n\t\t\t}\n\t\t} );\n\t} catch ( ParseException e ) {\n\t\tSystem.out.println(\"parse failed: \" + e.getMessage() + \"\\n\"\n\t\t\t+ \"Token Image: '\" + e.currentToken.image + \"'\\n\"\n\t\t\t+ \"Location: \" + e.currentToken.beginLine + \":\" + e.currentToken.beginColumn \n\t\t\t         + \"-\" + e.currentToken.endLine + \",\" + e.currentToken.endColumn);\n\t}\n\u003c/pre\u003e \n\nAn example that prints locations of all function definitions in a file may be found in\n\u003cpre\u003e\n\t\u003ca href=\"examples/jse/SampleParser.java\"\u003eexamples/jse/SampleParser.java\u003c/a\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nSee the \u003ca href=\"http://luaj.org/luaj/3.0/api/org/luaj/vm2/ast/package-summary.html\"\u003eorg.luaj.vm2.ast package\u003c/a\u003e javadoc for the API relating to the syntax tree that is produced. \n\n\u003ch1\u003e7 - \u003ca name=\"7\"\u003eBuilding and Testing\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003e\u003ca name=\"maven\"\u003eMaven integration\u003c/a\u003e\u003c/h2\u003e\nThe main jar files are now deployed in the maven central repository.  To use them in your maven-based project, list them as a dependency:\n\n\u003cp\u003e\nFor JSE projects, add this dependency for the luaj-jse jar:\n\u003cpre\u003e\n   \u0026lt;dependency\u0026gt;\n      \u0026lt;groupId\u0026gt;org.luaj\u0026lt;/groupId\u0026gt;\n      \u0026lt;artifactId\u0026gt;luaj-jse\u0026lt;/artifactId\u0026gt;\n      \u0026lt;version\u0026gt;3.0.2\u0026lt;/version\u0026gt;\n   \u0026lt;/dependency\u0026gt;\t\n\u003c/pre\u003e\nwhile for JME projects, use the luaj-jme jar:\n\u003cpre\u003e\n   \u0026lt;dependency\u0026gt;\n      \u0026lt;groupId\u0026gt;org.luaj\u0026lt;/groupId\u0026gt;\n      \u0026lt;artifactId\u0026gt;luaj-jme\u0026lt;/artifactId\u0026gt;\n      \u0026lt;version\u0026gt;3.0.2\u0026lt;/version\u0026gt;\n   \u0026lt;/dependency\u0026gt;\t\n\u003c/pre\u003e\n\nAn example skelton maven pom file for a skeleton project is in \n\u003cpre\u003e\n\t\u003ca href=\"examples/maven/pom.xml\"\u003eexamples/maven/pom.xml\u003c/a\u003e\n\u003c/pre\u003e\n\n\n\u003ch2\u003eBuilding the jars\u003c/h2\u003e\nAn ant file is included in the root directory which builds the libraries by default.\n\n\u003cp\u003e\nOther targets exist for creating distribution file an measuring code coverage of unit tests.\n\n\u003ch2\u003eUnit tests\u003c/h2\u003e\n\n\u003cp\u003e\nThe main luaj JUnit tests are organized into a JUnit 3 suite:\n\u003cpre\u003e\n\ttest/junit/org/luaj/vm2/AllTests.lua\n\u003c/pre\u003e\n\n\u003cp\u003e\nUnit test scripts can be found in these locations\n\u003cpre\u003e\n\ttest/lua/*.lua\n\ttest/lua/errors/*.lua\n\ttest/lua/perf/*.lua\n\ttest/lua/luaj3.0.2-tests.zip\n\u003c/pre\u003e\n\n\u003ch2\u003eCode coverage\u003c/h2\u003e\n\n\u003cp\u003e\nA build script for running unit tests and producing code coverage statistics is in \n\u003cpre\u003e\n\t\u003ca href=\"build-coverage.xml\"\u003ebuild-coverage.xml\u003c/a\u003e\n\u003c/pre\u003e\n\nIt relies on the cobertura code coverage library.\n\n\u003ch1\u003e8 - \u003ca name=\"8\"\u003eDownloads\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eDownloads and Project Pages\u003c/h2\u003e\nDownloads for all version available on SourceForge or LuaForge.  \nSources are hosted on SourceForge and available via sourceforge.net    \n\u003cbr/\u003e\n\u003cpre\u003e\n\t\u003ca href=\"http://luaj.sourceforge.net/\"\u003eSourceForge Luaj Project Page\u003c/a\u003e\n\t\u003ca href=\"http://sourceforge.net/project/platformdownload.php?group_id=197627\"\u003eSourceForge Luaj Download Area\u003c/a\u003e\n\u003c/pre\u003e\n\u003cp/\u003e\nThe jar files may also be downloaded from the maven central repository, see \u003ca href=\"#maven\"\u003eMaven Integration\u003c/a\u003e.\n\u003cp/\u003e\nFiles are no longer hosted at LuaForge.\n\n\u003ch1\u003e9 - \u003ca name=\"9\"\u003eRelease Notes\u003c/a\u003e\u003c/h1\u003e\n\n\u003ch2\u003eMain Changes by Version\u003c/h2\u003e\n\u003ctable cellspacing=\"10\"\u003e\u003ctr\u003e\u003ctd\u003e\u003ctable cellspacing=\"4\"\u003e\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e2.0\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eInitial release of 2.0 version \u003c/li\u003e  \n\u003c/ul\u003e\u003c/td\u003e\u003c/tr\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e2.0.1\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eImprove correctness of singleton construction related to static initialization \u003c/li\u003e\n\u003cli\u003eFix nan-related error in constant folding logic that was failing on some JVMs \u003c/li\u003e\n\u003cli\u003eJSR-223 fixes: add META-INF/services entry in jse jar, improve bindings implementation \u003c/li\u003e\n\u003c/ul\u003e\u003c/td\u003e\u003c/tr\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e2.0.2\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eJSR-223 bindings change: non Java-primitives will now be passed as LuaValue \u003c/li\u003e \n\u003cli\u003eJSR-223 enhancement: allow both \".lua\" and \"lua\" as extensions in getScriptEngine() \u003c/li\u003e\n\u003cli\u003eJSR-223 fix: use system class loader to support using luaj as JRE extension \u003c/li\u003e\n\u003cli\u003eImprove selection logic when binding to overloaded functions using luajava\u003c/li\u003e\n\u003cli\u003eEnhance javadoc, put it \u003ca href=\"docs/api/index.html\"\u003ein distribution\u003c/a\u003e \nand at \u003ca href=\"http://luaj.sourceforge.net/api/2.0/index.html\"\u003ehttp://luaj.sourceforge.net/api/2.0/\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eMajor refactor of luajava type coercion logic, improve method selection.\u003c/li\u003e \n\u003cli\u003eAdd luaj-sources-2.0.2.jar for easier integration into an IDE such as Netbeans \u003c/li\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e2.0.3\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eImprove coroutine state logic including let unreferenced coroutines be garbage collected \u003c/li\u003e\n\u003cli\u003eFix lua command vararg values passed into main script to match what is in global arg table \u003c/li\u003e\n\u003cli\u003eAdd arithmetic metatag processing when left hand side is a number and right hand side has metatable \u003c/li\u003e\n\u003cli\u003eFix load(func) when mutiple string fragments are supplied by calls to func \u003c/li\u003e\n\u003cli\u003eAllow access to public members of private inner classes where possible \u003c/li\u003e\n\u003cli\u003eTurn on error reporting in LuaParser so line numbers ar available in ParseException \u003c/li\u003e\n\u003cli\u003eImprove compatibility of table.remove() \u003c/li\u003e\n\u003cli\u003eDisallow base library setfenv() calls on Java functions \u003c/li\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e3.0\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eConvert internal and external API's to match lua 5.2.x environment changes \u003c/li\u003e\n\u003cli\u003eAdd bit32 library \u003c/li\u003e\n\u003cli\u003eAdd explicit Globals object to manage global state, especially to imrpove thread safety \u003c/li\u003e\n\u003cli\u003eDrop support for lua source to java surce (lua2java) in favor of direct java bytecode output (luajc) \u003c/li\u003e\n\u003cli\u003eRemove compatibility functions like table.getn(), table.maxn(), table.foreach(), and math.log10() \u003c/li\u003e\n\u003cli\u003eAdd ability to create runnable jar file from lua script with sample build file build-app.xml \u003c/li\u003e\n\u003cli\u003eSupply environment as second argument to LibFunction when loading via require() \u003c/li\u003e\n\u003cli\u003eFix bug 3597515 memory leak due to string caching by simplifying caching logic.\u003c/li\u003e\n\u003cli\u003eFix bug 3565008 so that short substrings are backed by short arrays.\u003c/li\u003e\n\u003cli\u003eFix bug 3495802 to return correct offset of substrings from string.find().\u003c/li\u003e\n\u003cli\u003eAdd artifacts to Maven central repository.\u003c/li\u003e\n\u003cli\u003eLimit pluggable scripting to use compatible bindings and contexts, implement redirection.\u003c/li\u003e\n\u003cli\u003eFix bug that didn't read package.path from environment.\u003c/li\u003e\n\u003cli\u003eFix pluggable scripting engine lookup, simplify implementation, and add unit tests.\u003c/li\u003e\n\u003cli\u003eCoerce script engine eval() return values to Java.\u003c/li\u003e\n\u003cli\u003eFix Lua to Java coercion directly on Java classes.\u003c/li\u003e\n\u003cli\u003eFix Globals.load() to call the library with an empty modname and the globals as the environment.\u003c/li\u003e\n\u003cli\u003eFix hash codes of double.\u003c/li\u003e\n\u003cli\u003eFix bug in luajava overload resolution.\u003c/li\u003e\n\u003cli\u003eFix luastring bug where parsing did not check for overflow.\u003c/li\u003e\n\u003cli\u003eFix luastring bug where circular dependency randomly caused NullPointerException.\u003c/li\u003e\n\u003cli\u003eMajor refactor of table implementation.\u003c/li\u003e\n\u003cli\u003eImproved behavior of next() (fixes issue #7).\u003c/li\u003e\n\u003cli\u003eExisting tables can now be made weak (fixes issue #16).\u003c/li\u003e\n\u003cli\u003eMore compatible allocation of table entries in array vs. hash (fixes issue #8).\u003c/li\u003e\n\u003cli\u003eFix os.time() to return a number of seconds instead of milliseconds.\u003c/li\u003e\n\u003cli\u003eImplement formatting with os.date(), and table argument for os.time().\u003c/li\u003e\n\u003cli\u003eLuaValue.checkfunction() now returns LuaFunction.\u003c/li\u003e\n\u003cli\u003eRefactor APIs related to compiling and loading scripts to provide methods on Globals.\u003c/li\u003e\n\u003cli\u003eAdd API to compile from Readers as well as InputStreams.\u003c/li\u003e\n\u003cli\u003eAdd optional -c encoding flag to lua, luac, and luajc tools to control source encoding.\u003c/li\u003e\n\u003cli\u003eLet errors thrown in debug hooks bubble up to the running coroutine.\u003c/li\u003e\n\u003cli\u003eMake error message handler function in xpcall per-thread instead of per-globals.\u003c/li\u003e\n\u003cli\u003eEstablish \"org.luaj.debug\" and \"org.luaj.luajc\" system properties to configure scripting engine.\u003c/li\u003e\n\u003cli\u003eAdd sample code for Android Application that uses luaj.\u003c/li\u003e\n\u003cli\u003eAdd sample code for Applet that uses luaj.\u003c/li\u003e\n\u003cli\u003eFix balanced match for empty string (fixes issue #23).\u003c/li\u003e\n\u003cli\u003ePass user-supplied ScriptContext to script engine evaluation (fixes issue #21).\u003c/li\u003e\n\u003cli\u003eAutoflush and encode written bytes in script contexts (fixes issue #20).\u003c/li\u003e\n\u003cli\u003eRename Globals.FINDER to Globals.finder.\u003c/li\u003e\n\u003cli\u003eFix bug in Globals.UTF8Stream affecting loading from Readers (fixes issue #24).\u003c/li\u003e\n\u003cli\u003eAdd buffered input for compiling and loading of scripts.\u003c/li\u003e\n\u003cli\u003eIn CoerceJavaToLua.coerse(), coerce byte[] to LuaString (fixes issue #31).\u003c/li\u003e\n\u003cli\u003eIn CoerceJavaToLua.coerse(), coerce LuaValue to same value (fixes issue #29).\u003c/li\u003e\n\u003cli\u003eFix line number reporting in debug stack traces (fixes issue #30).\u003c/li\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e3.0.1\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eFix __len metatag processing for tables.\u003c/li\u003e\n\u003cli\u003eAdd fallback to __lt when pocessing __le metatag.\u003c/li\u003e\n\u003cli\u003eConvert anonymous classes to inner classes (gradle build support).\u003c/li\u003e\n\u003cli\u003eAllow error() function to pass any lua object including non-strings.\u003c/li\u003e\n\u003cli\u003eFix string backing ownership issue when compiling many scripts.\u003c/li\u003e\n\u003cli\u003eMake LuaC compile state explicit and improve factoring.\u003c/li\u003e\n\u003cli\u003eAdd sample build.gradle file for Android example.\u003c/li\u003e\n\u003cli\u003ecollectgarbage() now behaves same as collectgarbage(\"collect\") (fixes issue #41).\u003c/li\u003e\n\u003cli\u003eAllow access to Java inner classes using lua field syntax (fixes issue #40).\u003c/li\u003e\n\u003cli\u003eList keyeq() and keyindex() methods as abstract on LuaTable.Entry (issue #37).\u003c/li\u003e\n\u003cli\u003eFix return value for table.remove() and table.insert() (fixes issue #39)\u003c/li\u003e\n\u003cli\u003eFix aliasing issue for some multiple assignments from varargs return values (fixes issue #38)\u003c/li\u003e\n\u003cli\u003eLet os.getenv() return System.getenv() values first for JSE, then fall back to properties (fixes issue #25)\u003c/li\u003e\n\u003cli\u003eImprove garbage collection of orphaned coroutines when yielding from debug hook functions (fixes issue #32).\u003c/li\u003e\n\u003cli\u003eLuaScriptEngineFactory.getScriptEngine() now returns new instance of LuaScriptEngine for each call.\u003c/li\u003e\n\u003cli\u003eFix os.date(\"*t\") to return hour in 24 hour format (fixes issue #45)\u003c/li\u003e\n\u003cli\u003eAdd SampleSandboxed.java example code to illustrate sandboxing techniques in Java.\u003c/li\u003e\n\u003cli\u003eAdd samplesandboxed.lua example code to illustrate sandboxing techniques in lua.\u003c/li\u003e\n\u003cli\u003eAdd CollectingOrphanedCoroutines.java example code to show how to deal with orphaned lua threads.\u003c/li\u003e\n\u003cli\u003eAdd LuajClassLoader.java and Launcher.java to simplify loading via custom class loader.\u003c/li\u003e\n\u003cli\u003eAdd SampleUsingClassLoader.java example code to demonstrate loading using custom class loader.\u003c/li\u003e\n\u003cli\u003eMake shared string metatable an actual metatable.\u003c/li\u003e\n\u003cli\u003eAdd sample code that illustrates techniques in creating sandboxed environments.\u003c/li\u003e\n\u003cli\u003eAdd convenience methods to Global to load string scripts with custom environment.\u003c/li\u003e\n\u003cli\u003eMove online docs to \u003ca href=\"http://luaj.org/luaj/3.0/api/index.html\"\u003ehttp://luaj.org/luaj/3.0/api/\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eFix os.time() conversions for pm times.\u003c/li\u003e\n\n\u003ctr valign=\"top\"\u003e\u003ctd\u003e\u0026nbsp;\u0026nbsp;\u003cb\u003e3.0.2\u003c/b\u003e\u003c/td\u003e\u003ctd\u003e\u003cul\u003e\n\u003cli\u003eFix JsePlatform.luaMain() to provide an \"arg\" table in the chunk's environment.\u003c/li\u003e\n\u003cli\u003eLet JsePlatform.luaMain() return values returned by the main chunk.\u003c/li\u003e\n\u003cli\u003eAdd synchronization to CoerceJavaToLua.COERCIONS map.\u003c/li\u003e\n\n\u003c/ul\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003ch2\u003eKnown Issues\u003c/h2\u003e\n\u003ch3\u003eLimitations\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003edebug code may not be completely removed by some obfuscators\n\u003cli\u003etail calls are not tracked in debug information\n\u003cli\u003emixing different versions of luaj in the same java vm is not supported\n\u003cli\u003evalues associated with weak keys may linger longer than expected\n\u003cli\u003ebehavior of luaj when a SecurityManager is used has not been fully characterized\n\u003cli\u003enegative zero is treated as identical to integer value zero throughout luaj\n\u003cli\u003elua compiled into java bytecode using luajc cannot use string.dump() or xpcall()\n\u003cli\u003enumber formatting with string.format() is not supported\n\u003cli\u003eshared metatables for string, bool, etc are shared across Globals instances in the same class loader\n\u003cli\u003eorphaned threads will not be collected unless garbage collection is run and sufficient time elapses\n\u003c/ul\u003e\n\u003ch3\u003eFile Character Encoding\u003c/h3\u003e\nSource files can be considered encoded in UTF-8 or ISO-8859-1 and results should be as expected, \nwith literal string contianing quoted characters compiling to the same byte sequences as the input. \n\nFor a non ASCII-compatible encoding such as EBSDIC, however, there are restrictions:\n\u003cul\u003e\n\u003cli\u003esupplying a Reader to Globals.load() is preferred over InputStream variants\n\u003cli\u003eusing FileReader or InputStreamReader to get the default OS encoding should work in most cases\n\u003cli\u003estring literals with quoted characters may not produce the expected values in generated code\n\u003cli\u003ecommand-line tools lua, luac, and luajc will require \u003cem\u003e-c Cp037\u003c/em\u003e to specify the encoding\n\u003c/ul\u003e\nThese restrictions are mainly a side effect of how the language is defined as allowing byte literals\nwithin literal strings in source files.\n\nCode that is generated on the fly within lua and compiled with lua's \u003cem\u003eload()\u003c/em\u003e function \nshould work as expected, since these strings will never be represented with the \nhost's native character encoding.\n","funding_links":[],"categories":["JVM语言","Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluaj%2Fluaj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluaj%2Fluaj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluaj%2Fluaj/lists"}