开源软件名称(OpenSource Name):torus/Lua-Objective-C-Bridge开源软件地址(OpenSource Url):https://github.com/torus/Lua-Objective-C-Bridge开源编程语言(OpenSource Language):C 60.4%开源软件介绍(OpenSource Introduction):Lua-Objective-C BridgeSynopsis
The Lua code above is equivalent to following Objective-C code:
More Example: https://github.com/torus/ios-lua-lander/blob/master/LuaLander/LuaLander/bootstrap.lua Requirements
UsageJust add following files to your project:
Samples/TestsPlease see LuaObjCBridge and LuaObjCBridgeMac projects. Objective-C APIFirst, import Lua and the bridge header files:
Then,
gets the lua_State object to call Lua functions. High-Level Lua API
Creates a new context.
Returns wrapped Objective-C object. Then, you can send a message to the object like:
You need to unwrap the object to pass to a method using
Any Objective-C class object can be obtained via
Returns the UIWebView class object. Extending the BridgeLuaBridge uses a stack to share objects between Lua and Objective-C. And some operators are defined to handle stuff in the stack. You can add user-defined operators to the LuaBridge class folloing this signature:
Low-Level Lua APInewstack
Returns a new stack to pass and receive paramters between Lua and Objective-C. push
Pushes one or more arguments to the stack. pop
Pops the last (top) value from the stack. operate
Calls given operator with the content of the stack. getclass
Returns the class object for given class name. Data Type Conversion
Pre-defined Operatorscall
"call" operator sends a method specified by selector to the target, then pushes the returned object. Please note that the argments must be pushed in reverse order. This is equivalent to following Objective-C expression:
Adding OperatorsCreate a category on the LuaBrige class and implement your operators in folloing signature:
Then from Lua script call the operator like this:
Note that in Objective-C, the method name should be "op_your_operator:". LicenseThe MIT License (MIT) Copyright (c) 2015 Toru Hisai Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. AuthorToru Hisai toru@torus.jp @torus |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论