{"id":13813021,"url":"https://github.com/vimfung/LuaScriptCore","last_synced_at":"2025-05-14T22:31:34.399Z","repository":{"id":37451092,"uuid":"63399083","full_name":"vimfung/LuaScriptCore","owner":"vimfung","description":"一款简单易用的多平台Lua桥接器，目前支持在iOS、Mac OS X、Android以及Unity3D中使用，让原生环境与Lua无障碍沟通。","archived":false,"fork":false,"pushed_at":"2020-12-18T21:49:19.000Z","size":32801,"stargazers_count":512,"open_issues_count":21,"forks_count":115,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-04-22T22:41:53.838Z","etag":null,"topics":["android","ios","lua","osx","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C","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/vimfung.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":"2016-07-15T06:55:01.000Z","updated_at":"2025-02-26T16:10:08.000Z","dependencies_parsed_at":"2022-08-19T12:40:43.929Z","dependency_job_id":null,"html_url":"https://github.com/vimfung/LuaScriptCore","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimfung%2FLuaScriptCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimfung%2FLuaScriptCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimfung%2FLuaScriptCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimfung%2FLuaScriptCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimfung","download_url":"https://codeload.github.com/vimfung/LuaScriptCore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254239619,"owners_count":22037738,"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","ios","lua","osx","unity3d"],"created_at":"2024-08-04T04:01:00.258Z","updated_at":"2025-05-14T22:31:29.356Z","avatar_url":"https://github.com/vimfung.png","language":"C","readme":"# 功能\u0026特点\n\nLuaScriptCore旨在能够在多种平台上方便地使用Lua。其提供了与多种平台的功能交互，让开发者无须关心Lua与各个平台之间是实现交互的细节，只需要根据自己的业务需求，使用LuaScriptCore提供的方法，轻松简单地实现各种功能。如：\n\n* **原生代码调用Lua中的方法和变量，控制Lua的业务逻辑**\n\n如，Lua中有如下定义\n\n```lua\nurl = \"https://vimfung.github.io/LuaScriptCore/\";\n\nfunction printUrl(url)\n\n  print (url);\n\nend\n```\n\n在原生代码中可以如下面操作Lua变量和方法:\n\n**iOS/OSX**\n\n```objc\n//获取变量\nLSCValue *urlValue = [context getGlobalForName:@\"url\"];\nNSLog(@\"url = %@\", [urlValue toString]);\n\n//调用方法\n[context callMethodWithName:\"printUrl\" arguments:@[urlValue]];\n```\n\n**Android**\n\n```java\n//获取变量\nLuaValue urlValue = context.getGlobal(\"url\");\nLog.d(\"LuaScriptCore\", String.format(\"url = %s\", urlValue.toString()));\n\n//调用方法\ncontext.callMethod(\"printUrl\", new LuaValue[] {urlValue});\n```\n\n**Unity3D**\n\n```csharp\n//获取变量\nLuaValue urlValue = context.getGlobal (\"url\");\nDebug.LogFormat (\"url = {0}\", urlValue.toString ());\n\n//调用方法\ncontext.callMethod(\"printUrl\", new List\u003cLuaValue\u003e(new LuaValue[] {urlValue}));\n```\n\n* **Lua中调用原生提供的方法，让一些Lua无法处理或者耗时的处理交由原生方法实现**\n\n如，原生代码为Lua定义输出日志方法log：\n\n**iOS/OSX**\n\n```objc\n[context registerMethodWithName:@\"log\" block:^LSCValue *(NSArray\u003cLSCValue *\u003e *arguments) {\n       \n  NSLog(@\"%@\", [arguments[0] toString]);\n  return nil;\n  \n}];\n```\n\n**Android**\n\n```java\ncontext.registerMethod(\"log\", new LuaMethodHandler() {\n\n  @Override\n  public LuaValue onExecute(LuaValue[] arguments) {       \n    Log.d(\"LuaScriptCore\", arguments[0].toString());\n    return null;\n  }\n  \n});\n```\n\n**Unity3D**\n\n```csharp\nLuaContext.currentContext.registerMethod(\"log\", (List\u003cLuaValue\u003e arguments) =\u003e {\n\n  Debug.Log(arguments[0].toString());\n  return null;\n\n});\n```\n\n在Lua中则可以调用该方法：\n\n```lua\nlog(\"Hello World\");\n```\n\n* **原生代码定义类型直接映射到Lua中使用，让Lua更方便地实现面向对象的编程**\n\n原生代码有如下类型定义：\n\n**iOS**\n\n```objc\n@interface LuaType : NSObject \u003cLSCExportType\u003e\n\n// 定义属性和方法...\n\n@end\n```\n\n**Android**\n\n```java\nclass LuaType implements LuaExportType\n{\n// 定义属性和方法...\n}\n```\n\n**Unity3D**\n\n```csharp\nclass LuaType : LuaExportType \n{\n// 定义属性和方法...\n}\n```\n\n则可以在Lua中进行使用，如：\n\n```lua\nlocal obj = LuaType();\nprint (obj);\n```\n\n# 如何使用\n\n## iOS / OS X 平台\n\n关于iOS／OS X平台下如何使用LuaScriptCore，请参考《[iOS/OS X集成使用文档](https://github.com/vimfung/LuaScriptCore/wiki/iOS\u0026OS-X%E9%9B%86%E6%88%90%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3)》\n\n## Android 平台\n\n关于Android平台下如何使用LuaScriptCore，请参考《[Android集成使用文档](https://github.com/vimfung/LuaScriptCore/wiki/Android%E9%9B%86%E6%88%90%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3)》\n\n## Unity3D\n\n关于Unity3D下如何使用LuaScriptCore，请参考《[Unity3D集成使用文档](https://github.com/vimfung/LuaScriptCore/wiki/Unity3D%E9%9B%86%E6%88%90%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3)》\n\n# 注意\n\n目前源码中不带有任何平台的Release库，在运行Sample时需要从[Relases](https://github.com/vimfung/LuaScriptCore/releases)页签中下载最新版本的库并放入Sample项目后运行。\n\n# API文档\n\n- iOS / OS X [[Objective-C](https://github.com/vimfung/LuaScriptCore/wiki/API%E6%96%87%E6%A1%A3_iOS-OS-X_Objective-C)] [[Swift](https://github.com/vimfung/LuaScriptCore/wiki/API%E6%96%87%E6%A1%A3_iOS-OS-X_Swift)]\n- Android [[Java](https://github.com/vimfung/LuaScriptCore/wiki/API%E6%96%87%E6%A1%A3_Android_Java)]\n- Unity3D [[C#](https://github.com/vimfung/LuaScriptCore/wiki/API%E6%96%87%E6%A1%A3_Unity3D_CS)]\n\n# 最近更新\n\n## Release 2.4.0 - [下载](https://github.com/vimfung/LuaScriptCore/releases/tag/2.4.0)\n\n更新内容：\n\n1. 新增线程执行功能，可以通过LuaContext的runThread方法将一个lua方法执行在不同的线程中。\n2. LuaValue新增setObject方法，允许直接为table对象设置和删除键值对，而不是通过返回值的方法进行调整。\n3. 新增LuaContext的脚本执行控制接口，可以通过LuaScriptController来强制中断脚本执行。\n4. iOS / OSX 平台下增加初始化上下文时传入配置接口，允许导出类方法名称时使用完整名称。\n5. 优化addSearchPath方法，可以加入lua文件以外的文件路径\n6. 优化Android和Unity3D下的抛出Lua异常操作\n7. 修复抛出异常时导致内存泄漏和程序死锁问题\n8. 修复iOS / OSX 平台下使用Swift的@objc导出类无法找到问题\n9. 修复Android平台下传递数组中包含导出类型对象时产生JNI栈溢出问题。\n10. 修复Android平台下，从原生层传入基础类型数组时无法转换到lua中使用问题。\n11. 修复Android平台下LuaValue无法识别传入byte[]类型问题。\n12. 修复Android平台下，对象方法传入float、int、long类型参数时无法识别问题。\n13. 修复Android平台下，对象方法返回值为float时无法识别问题。\n14. 修复Android平台下LuaTuple返回基础类型值不正确问题\n15. 修复Android平台下LuaTuple设置List类型为返回值时获取不到列表内容问题\n16. 修复Android平台下循环调用方法时导致崩溃问题\n17. 修复Android平台下创建类对象是内存泄漏问题\n18. 修复Unity3D下LuaValue转换为object时，如果数据为数组或者字典里面的元素没有解包问题。\n\n## [更多更新历史](https://github.com/vimfung/LuaScriptCore/wiki/%E6%9B%B4%E6%96%B0%E5%8E%86%E5%8F%B2)\n\n# 建议\u0026支持\n\n如问题请[与我联系](mailto:luascriptcore@163.com)\n\n![QQ技术讨论群](https://cloud.githubusercontent.com/assets/3739609/22011176/a05d3ca6-dcc8-11e6-8378-6ff68fb0ab9c.png)\n\n# 赞助\n\n打开支付宝扫一扫，给予我支持\n\n![打开支付宝扫一扫](https://user-images.githubusercontent.com/3739609/33522029-5dad4d50-d81d-11e7-848d-7f224f8e737d.jpg)\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimfung%2FLuaScriptCore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimfung%2FLuaScriptCore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimfung%2FLuaScriptCore/lists"}