{"id":16651839,"url":"https://github.com/henry232323/async-lua-embed","last_synced_at":"2025-12-25T15:34:25.545Z","repository":{"id":41263178,"uuid":"508577555","full_name":"henry232323/async-lua-embed","owner":"henry232323","description":"Embed Lua in Python with access to Python's async functions","archived":false,"fork":false,"pushed_at":"2022-09-27T05:34:42.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T08:46:36.629Z","etag":null,"topics":["async","asyncio","discord","lua","python"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/henry232323.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}},"created_at":"2022-06-29T06:45:39.000Z","updated_at":"2022-07-04T00:49:43.000Z","dependencies_parsed_at":"2022-09-20T23:31:11.486Z","dependency_job_id":null,"html_url":"https://github.com/henry232323/async-lua-embed","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry232323%2Fasync-lua-embed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry232323%2Fasync-lua-embed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry232323%2Fasync-lua-embed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henry232323%2Fasync-lua-embed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henry232323","download_url":"https://codeload.github.com/henry232323/async-lua-embed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243248103,"owners_count":20260748,"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":["async","asyncio","discord","lua","python"],"created_at":"2024-10-12T09:26:45.453Z","updated_at":"2025-12-25T15:34:25.494Z","avatar_url":"https://github.com/henry232323.png","language":"Lua","readme":"# Async Lua Embed\nThis small package is intended to provide the tools to allow the embedding of user generated scripts into \nan async environment. This package allows the definition and execution of asynchronous Python functions\nand methods in the user defined scripts, which may allow users to interface with things like Discord bot\n\n### Installation\n\n```shell\npython -m pip install git+https://github.com/henry232323/async-lua-embed\n```\n\n### Example\nFor an example of most of the package's functionality:\n\n```python\nimport asyncio\nimport aiohttp as aiohttp\nfrom async_lua import DAO, Environment, CommandExecutor\n\n\nclass Pokemon(DAO):\n  def __init__(self, dispatch, name):\n    super().__init__(dispatch)\n    self.name: str = name\n\n  async def get_type(self):\n    async with aiohttp.ClientSession() as session:\n      data = await session.get(f\"https://pokeapi.co/api/v2/pokemon/{self.name}\")\n      js = await data.json()\n      return js[\"types\"][0][\"type\"][\"name\"]\n\n\nclass ApiEnvironment(Environment):\n  def __init__(self, exec, dispatch):\n    super().__init__(exec, dispatch)\n\n    self.register(\"ditto\", Pokemon(dispatch, \"ditto\"))\n\n  async def say(self, *args):\n    \"\"\"Prints a message\"\"\"\n    print(*args)\n\n\ncode = \"\"\"\nsay(ditto.get_type())\n\"\"\"\n\n\nasync def context():\n  exec = CommandExecutor()\n  exec.register_env(ApiEnvironment)\n  await exec.execute(code)\n\n\nasyncio.get_event_loop().run_until_complete(context())\n\n```\n\n### Sandboxing\nThis library implements a simple sandbox based on some of the links below, including the final\nmodule wholesale.\n- https://stackoverflow.com/questions/1224708/how-can-i-create-a-secure-lua-sandbox\n- https://github.com/scoder/lupa/issues/47\n- https://github.com/scrapinghub/splash/blob/master/splash/lua_modules/sandbox.lua\n\n### Model\n- Open an executor in which the Lua will be executed\n- Run all Lua in an elaborate sandbox limiting access, memory, and number of instructions\n- No need to kill threads when the sandbox (hopefully) manages itself\n- A DAO is intended to be a surrogate for seamlessly embedding async functions into an object, allowing control\nover the object with Python implemented async functions\n- Asynchronous nature is maintained by suspending execution with coroutines until async completes\n  - Commands are yielded by the coroutine, processed, and sent back into the coro\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenry232323%2Fasync-lua-embed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenry232323%2Fasync-lua-embed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenry232323%2Fasync-lua-embed/lists"}