{"id":16202266,"url":"https://github.com/dingyi222666/androlua-standalone","last_synced_at":"2025-07-03T18:09:29.635Z","repository":{"id":57733017,"uuid":"470986381","full_name":"dingyi222666/AndroLua-Standalone","owner":"dingyi222666","description":"在android上运行lua","archived":false,"fork":false,"pushed_at":"2022-05-21T09:39:39.000Z","size":1713,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-15T21:15:35.297Z","etag":null,"topics":["android","androlua","lua","luajava"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/dingyi222666.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-03-17T12:32:29.000Z","updated_at":"2025-06-10T01:03:39.000Z","dependencies_parsed_at":"2022-09-26T22:30:39.921Z","dependency_job_id":null,"html_url":"https://github.com/dingyi222666/AndroLua-Standalone","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/dingyi222666/AndroLua-Standalone","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dingyi222666%2FAndroLua-Standalone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dingyi222666%2FAndroLua-Standalone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dingyi222666%2FAndroLua-Standalone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dingyi222666%2FAndroLua-Standalone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dingyi222666","download_url":"https://codeload.github.com/dingyi222666/AndroLua-Standalone/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dingyi222666%2FAndroLua-Standalone/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260109356,"owners_count":22960015,"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":["android","androlua","lua","luajava"],"created_at":"2024-10-10T09:46:44.218Z","updated_at":"2025-07-03T18:09:29.587Z","avatar_url":"https://github.com/dingyi222666.png","language":"Kotlin","readme":"## AndoroLua-Standalone\n\n本项目是AndroLua+的单独剥离版，项目只需要引用单个模块，即可低耦合的使用LuaJava,让luajava使用更简易。\n\n提示:本项目并不能直接运行androlua+的代码，java层修改了代码，导致相应的很多函数都需要重写\n\n### 特性\n\n- 低耦合的使用方式\n\n### 使用方式\n\n\u003e 首先接入androlua-standlone到当前项目\n\n```groovy\nimplementation \"io.github.dingyi222666:androlua-standlone:1.0.4\"\n```\n\n\u003e 在项目的Application的onCreate方法里初始化LuaGlobal\n\n```kotlin\n//kotlin\nLuaGlobal.init(this)\n```\n\n接下来可选多种使用vm的方式\n\n#### SingleLuaVM\n\nSingleLuaVM 是简单低耦合的运行单个lua虚拟机的类，无需为虚拟机设置lua运行路径以及lua目录即可运行lua代码\n\n\u003e 创建类\n\n```kotlin\nval vm = SingleLuaVM()\n```\n\n\u003e 运行代码\n\n```kotlin\n\n//假设 当前类有个print方法，接收一个String\nvm.set(\"javaObject\",this)\n//调用print方法\nvm.doString(\"javaObject.print 'hello luavm' \")\n\n```\n\n#### LuaActivityVM\n\nLuaActivityVM 是 类似于AndroLua+ LuaActivity的 一类 VM对象，可以传递activity，使得lua拥有操作activity的能力\n\n\u003e 创建类\n\n目前只推荐通过继承ProxyActivity来使用该类型的VM\n\n以下代码就继承了ProxyLuaActivity,并且指定了默认的运行lua路径\n\n```kotlin\n//import zip4j\nimport net.lingala.zip4j.ZipFile\n\nclass MainActivity : ProxyLuaActivity(\n    luaDir = LuaGlobal.applicationContext.getExternalFilesDir(\"test\")?.parentFile?.absolutePath.toString()\n)\n```\n\n\u003e 覆盖获取Lua运行路径方法\n\n接下来你可以覆盖getRunLuaPath方法 返回运行的lua文件的路径 如果文件不为绝对路径，那么久采用相对路径，即luadir+路径 该方法仅会在runOnCreate时调用\n\n```kotlin\n override fun getRunLuaPath(): String {\n    return \"main.lua\"\n}\n```\n\n\u003e 覆盖onCreate方法\n\n然后覆盖onCreate方法 实现你的解压lua文件逻辑\n\n这里需要注意是解压完之后需要调用 runOnCreate(savedInstanceState) 方法来实现默认的调用lua文件逻辑\n\n```kotlin\n override fun onCreate(savedInstanceState: Bundle?) {\n\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.activity_main)\n\n\n    //Un Assets File\n    val assetsPath = getExternalFilesDir(\"test\")?.parentFile?.absolutePath.toString()\n\n    // get apk path\n    val apkPath = this.packageResourcePath\n\n    //create and use apk\n    lifecycleScope.launch {\n        //run on io thread\n        withContext(Dispatchers.IO) {\n            ZipFile(apkPath).use { apkFile -\u003e\n                apkFile\n                    .fileHeaders\n                    .filter { it.fileName.startsWith(\"assets/\") \u0026\u0026 it.isDirectory.not() }\n                    .forEach {\n                        apkFile\n                            .extractFile(\n                                it,\n                                assetsPath,\n                                it.fileName.substring(\"assets/\".length)\n                            )\n                    }\n            }\n        }\n        runOnCreate(savedInstanceState)\n    }\n\n}\n```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdingyi222666%2Fandrolua-standalone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdingyi222666%2Fandrolua-standalone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdingyi222666%2Fandrolua-standalone/lists"}