{"id":25777166,"url":"https://github.com/mjanicek/rembulan","last_synced_at":"2025-02-27T06:07:18.652Z","repository":{"id":57721178,"uuid":"65250538","full_name":"mjanicek/rembulan","owner":"mjanicek","description":"Rembulan, an implementation of Lua 5.3 for the Java Virtual Machine","archived":false,"fork":false,"pushed_at":"2020-04-22T00:57:27.000Z","size":8092,"stargazers_count":160,"open_issues_count":25,"forks_count":27,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-04-25T12:32:01.644Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjanicek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-09T00:55:04.000Z","updated_at":"2024-04-10T21:07:43.000Z","dependencies_parsed_at":"2022-09-04T16:20:54.633Z","dependency_job_id":null,"html_url":"https://github.com/mjanicek/rembulan","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjanicek%2Frembulan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjanicek%2Frembulan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjanicek%2Frembulan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjanicek%2Frembulan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjanicek","download_url":"https://codeload.github.com/mjanicek/rembulan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240987435,"owners_count":19889335,"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":[],"created_at":"2025-02-27T06:01:38.067Z","updated_at":"2025-02-27T06:07:18.645Z","avatar_url":"https://github.com/mjanicek.png","language":"Java","funding_links":[],"categories":["JVM实现","Languages"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mjanicek/rembulan.svg?branch=master)](https://travis-ci.org/mjanicek/rembulan)\n\n# Rembulan\n\n(*Rembulan* is Javanese/Indonesian for *Moon*.)\n\n\n## About\n\nRembulan is an implementation of Lua 5.3 for the Java Virtual Machine (JVM), written in\npure Java with minimal dependencies.\nThe goal of the Rembulan project is to develop a correct, complete and scalable Lua\nimplementation for running sandboxed Lua programs on the JVM.\n\nRembulan implements Lua 5.3 as specified by the\n[Lua Reference Manual](http://www.lua.org/manual/5.3/manual.html), explicitly attempting to mimic\nthe behaviour of PUC-Lua whenever possible. This includes language-level features (such\nas metamethods and coroutines) and the standard library.\n\n\n## Status\n\nThe majority of language-level features is implemented, and may be expected\nto work. If you find behaviour that does not conform to Lua 5.3 as defined by the Lua Reference\nManual, please [open a new issue](https://github.com/mjanicek/rembulan/issues).\n\nSee also the [completeness table](doc/CompletenessTable.md) that maps out the current\ncompleteness status of Rembulan with regard to PUC-Lua, in particular the standard library.\n\n## Frequently asked questions (FAQ)\n\n#### What is Rembulan good for?\n\nLua is a small, beautifully-designed and simple-yet-powerful programming language.\nLua has been traditionally used as an embedded scripting language. Rembulan aims to serve\na similar purpose on the JVM, with an explicit focus on sandboxing the client Lua programs.\n\nThere are two main use-cases for Rembulan: running untrusted Lua scripts on the JVM,\nand enhancing Java applications by adding the ability to script them with Lua.\n\n#### Does Rembulan implement the Lua C API?\n\nNo, at this point Rembulan requires libraries to be written against its Java interface.\n \n#### Does Rembulan work with Lua bytecode?\n\nNo. The Lua bytecode (i.e., the bytecode generated by PUC-Lua's `luac`) is considered\nan implementation detail by both Rembulan and the Lua Reference Manual. Rembulan implements\nits own compiler and compiles to Java bytecode directly. It uses its own\nintermediate representation (IR) annotated with statically-inferred type information,\nbut does not expose it to the user, and the IR has no serialisable form.\n \nFor more information about the Rembulan compiler, see the\n[compiler overview](doc/CompilerOverview.md). \n \n#### How are coroutines implemented?\n \nSee [How are coroutines implemented?](doc/CoroutinesOverview.md)  \n\n## Using Rembulan\n\nRembulan requires a Java Runtime Environment (JRE) version 7 or higher.\n\n### Documentation\n\nGenerated JavaDocs are available online:\n\n * [Runtime module](https://mjanicek.github.io/rembulan/apidocs/rembulan-runtime/index.html)\n * [Compiler](https://mjanicek.github.io/rembulan/apidocs/rembulan-compiler/index.html)\n * [Standard Library](https://mjanicek.github.io/rembulan/apidocs/rembulan-stdlib/index.html)\n\nThere are also a few short texts in the `doc` folder:\n\n * [How are coroutines implemented?](doc/CoroutinesOverview.md)\n * [Overview of the Rembulan compiler](doc/CompilerOverview.md)\n * [Rembulan completeness table](doc/CompletenessTable.md)\n\n### Building from source\n\nTo build Rembulan, you will need the following:\n\n * Java Development Kit (JDK) version 7 or higher\n * Maven version 3 or higher\n\nMaven will pull in the remaining dependencies as part of the build process.\n\nTo fetch the latest code on the `master` branch and build it, run\n\n```sh\ngit clone https://github.com/mjanicek/rembulan.git\ncd rembulan    \nmvn install\n```\n\nThis will build all modules, run tests and finally install all artifacts into your local\nMaven repository.    \n\n#### Standalone REPL\n\nMuch like PUC-Lua, Rembulan contains a standalone REPL. This is provided in the module\n`rembulan-standalone`. To build the REPL, run\n\n```sh\nmvn package -DskipTests -Dmaven.javadoc.skip=true -DstandaloneFinalName=rembulan\n```\n\nThe standalone REPL is packaged as a self-contained, executable [Capsule](http://www.capsule.io)\nand is placed in the directory `rembulan-standalone/target`.\n \nTo run the REPL:\n\n```sh\ncd rembulan-standalone/target\n./rembulan-capsule.x\n```\n\nThe standalone REPL mimics the behaviour or the standalone PUC-Lua interpreter and may be\nused as its drop-in replacement.\n\n```\n$ ./rembulan-capsule.x\nRembulan 0.1-SNAPSHOT (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60)\n\u003e print(\"hello world!\")\nhello world!\n```\n\n### Using Rembulan from Maven\n\nThere are no releases yet, but snapshot artifacts are published to the Sonatype OSSRH Snapshot\nRepository. To use the snapshot artifacts, add the following configuration to your `pom.xml`:\n\n```xml\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003esonatype-ossrh-snapshots\u003c/id\u003e\n    \u003cname\u003eSonatype OSSRH (Snapshots)\u003c/name\u003e\n    \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots/\u003c/url\u003e\n    \u003csnapshots /\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\nTo include the **runtime** as a dependency:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.sandius.rembulan\u003c/groupId\u003e\n  \u003cartifactId\u003erembulan-runtime\u003c/artifactId\u003e\n  \u003cversion\u003e0.1-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nTo include the **compiler** as a dependency:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.sandius.rembulan\u003c/groupId\u003e\n  \u003cartifactId\u003erembulan-compiler\u003c/artifactId\u003e\n  \u003cversion\u003e0.1-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nTo include the **standard library** as a dependency:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.sandius.rembulan\u003c/groupId\u003e\n  \u003cartifactId\u003erembulan-stdlib\u003c/artifactId\u003e\n  \u003cversion\u003e0.1-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nNote that `rembulan-compiler` and `rembulan-stdlib` both pull in `rembulan-runtime` as\na dependency, but are otherwise independent. (I.e., to use the compiler and the standard\nlibrary, you need to declare both `-compiler` and `-stdlib` as dependencies, but do not need\nto include `-runtime`).\n\n## Getting started\n\nRembulan compiles Lua functions into Java classes and loads them into the JVM;\nthe compiler performs a type analysis of the Lua programs in order to generate a more\ntightly-typed code whenever feasible.\n\nSince the JVM does not directly support coroutines, Rembulan treats Lua functions as state\nmachines and controls their execution (i.e., yields, resumes and pauses) using exceptions.\nSince the Rembulan runtime retains control of the control state, this technique is also used\nto implement CPU accounting and scheduling of asynchronous operations.\n\n#### Example: Hello world  \n\nThe following snippet loads the Lua program `print('hello world!')`, compiles it, loads\nit into a (non-sandboxed) state, and runs it:\n\n(From [`rembulan-examples/.../HelloWorld.java`](rembulan-examples/src/main/java/net/sandius/rembulan/examples/HelloWorld.java))\n\n```java\nString program = \"print('hello world!')\";\n\n// initialise state\nStateContext state = StateContexts.newDefaultInstance();\nTable env = StandardLibrary.in(RuntimeEnvironments.system()).installInto(state);\n\n// compile\nChunkLoader loader = CompilerChunkLoader.of(\"hello_world\");\nLuaFunction main = loader.loadTextChunk(new Variable(env), \"hello\", program);\n\n// execute\nDirectCallExecutor.newExecutor().call(state, main);\n```\n\nThe output (printed to `System.out`) is:\n\n```\nhello world!\n```\n\n#### Example: CPU accounting\n\nLua functions can be called in a mode that automatically pauses their execution once the\ngiven number of operations has been performed:\n\n(From [`rembulan-examples/.../InfiniteLoop.java`](rembulan-examples/src/main/java/net/sandius/rembulan/examples/InfiniteLoop.java))\n\n```java\nString program = \"n = 0; while true do n = n + 1 end\";\n\n// initialise state\nStateContext state = StateContexts.newDefaultInstance();\nTable env = StandardLibrary.in(RuntimeEnvironments.system()).installInto(state);\n\n// compile\nChunkLoader loader = CompilerChunkLoader.of(\"infinite_loop\");\nLuaFunction main = loader.loadTextChunk(new Variable(env), \"loop\", program);\n\n// execute at most one million ops\nDirectCallExecutor executor = DirectCallExecutor.newExecutorWithTickLimit(1000000);\n\ntry {\n    executor.call(state, main);\n    throw new AssertionError();  // never reaches this point!\n}\ncatch (CallPausedException ex) {\n    System.out.println(\"n = \" + env.rawget(\"n\"));\n}\n```\n\nPrints:\n\n```\nn = 199999\n```\n\nThe [`CallPausedException`](https://mjanicek.github.io/rembulan/apidocs/rembulan-runtime/net/sandius/rembulan/exec/CallPausedException.html) contains a *continuation* of the call. The call can be resumed:\nthe pause is transparent to the Lua code, and the loop does not end with an error (it is merely\npaused).\n\n#### Further examples\n\nFor further examples, see the classes in\n[`rembulan-examples/src/main/java/net/sandius/rembulan/examples`](rembulan-examples/src/main/java/net/sandius/rembulan/examples).\n\n### Project structure\n\nRembulan is a multi-module Maven build, consisting of the following modules that are deployed\nto Sonatype OSSRH:\n\n * `rembulan-runtime` ... the core classes and runtime;\n * `rembulan-compiler` ... a compiler of Lua sources to Java bytecode;\n * `rembulan-stdlib` ... the Lua standard library;\n * `rembulan-standalone` ... standalone REPL, a (mostly) drop-in replacement\n                             for the `lua` command from PUC-Lua.\n\nThere are also auxiliary modules that are not deployed:\n\n * `rembulan-tests` ... project test suite, including benchmarks from\n                        the Benchmarks Game;\n * `rembulan-examples` ... examples of the Rembulan API.                       \n\n\n## Contributing\n\nContributions of all kinds are welcome!\n\n\n## License\n\nRembulan is licensed under the Apache License Version 2.0. See the file\n[LICENSE.txt](LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjanicek%2Frembulan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjanicek%2Frembulan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjanicek%2Frembulan/lists"}