KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
luaj-android
★ 23
Open GitHub ↗
luaj procject for android.
Download README (.md)
Explore Similar Repositories
mds
:
Modern Data Science
Object-Detection-from-SAR-images-using-DCNN
:
No description available.
ViperTwitterClient
:
Twitter client app for VIPER design pattern implementation
BasicAlgorithms
:
Basic algorithms implementations in C#
narchive
:
A command-line app for creating and extracting NARC archives, a format commonly used in Nintendo DS games.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
luaj-android
?
Download (.md)
# luaj安卓框架 本项目由[luaj](https://github.com/luaj/luaj)的`jse`版本为基础修改而来。语法上与`luaj`并无不一样,主要修改了几处安卓平台上的引用错误。 ## 文档 [说明文档](doc/README.md) ## 简单使用 ### 引入库 ``` compile 'com.reizx:luaj-android:3.0.4' ``` ### JAVA调用LUA例子 以下例子都会输出以`luaj-tag`为tag的日志。 #### 执行文件([demo](app\src\main\java\com\reizx\luaj\view\fragment\HomeFragment.java)) 调用方法: ``` public void invokeFile() { String path = "/sdcard/SimpleExample.lua"; // copy the script to path ResourceUtils.copyFileFromAssets("SimpleExample.lua", path); // init global before // create an environment to run in // Globals globals = JsePlatform.standardGlobals(); // Use the convenience function on Globals to load a chunk. LuaValue chunk = globals.loadfile(path); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.invoke(); } ``` SimpleExample.lua ``` --- --- 例子执行请执行rlua模块中AndroidTest的SimpleExample测试用例 --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by kig. --- DateTime: 2018/3/6 17:34 --- -- 引入类 LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 -- 调用类的静态接口 LuajLog:d("hello luaj...1") LuajLog:d("hello luaj...2") LuajLog:d("hello luaj...3") ``` #### 执行脚本流 ``` public void invokeStream() { String path = "/sdcard/SimpleExample.lua";//请查看"执行文件"中的SimpleExample.lua // get the script InputStream InputStream in = new ByteArrayInputStream(ResourceUtils.readAssets2String("SimpleExample.lua").getBytes()); // init global before // create an environment to run in // Globals globals = JsePlatform.standardGlobals(); // Use the convenience function on Globals to load a chunk. /** Load the content form an input stream as a binary chunk or text file. * @param is InputStream containing a lua script or compiled lua" * @param chunkname Name that will be used within the chunk as the source. * @param mode String containing 'b' or 't' or both to control loading as binary or text or either. * @param environment LuaTable to be used as the environment for the loaded function. * */ LuaValue chunk = globals.load(in, "@"+"Simple", "bt", globals); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.invoke(); } ``` #### 自定义接口 ``` public void invokeCustom(){ Globals globals = customEvn(); // get the script InputStream InputStream in = new ByteArrayInputStream(ResourceUtils.readAssets2String("hyperbolicapp.lua").getBytes()); LuaValue chunk = globals.load(in, "@"+"hyperbolicapp", "bt", globals); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.invoke(); } /** * 自定义lua环境,可以自定义API * @return */ public Globals customEvn(){ Globals globals = new Globals(); globals.load(new JseBaseLib()); globals.load(new PackageLib()); globals.load(new Bit32Lib()); globals.load(new TableLib()); globals.load(new StringLib()); globals.load(new CoroutineLib()); globals.load(new JseMathLib()); globals.load(new JseIoLib()); globals.load(new JseOsLib()); globals.load(new LuajavaLib()); //todo register library globals.load(new hyperbolic()); LoadState.install(globals); LuaC.install(globals); return globals; } ``` hyperbolicapp.lua ``` -- Sample luaj code to try loading and executing the 'hyperbolic' sample library -- -- The sample library source is in examples/jse/hyperbolic.java. -- For this sample to work, that source must be compiled, and the class must -- be on the class path. -- -- First load the library via require(). This will call the public constructor -- for the class named 'hyperbolic' if it exists, and then initialize the -- library by invoking LuaValue.call('hyperbolic') on that instance require 'hyperbolic' LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 -- Test that the table is in the globals, and the functions exist. -- LuajLog:d('hyperbolic : '..hyperbolic) -- LuajLog:d('hyperbolic.sinh : '..hyperbolic.sinh) -- LuajLog:d('hyperbolic.cosh : '..hyperbolic.cosh) -- Try exercising the functions. LuajLog:d('sinh(0.5) : '..hyperbolic.sinh(0.5)) LuajLog:d('cosh(0.5) : '..hyperbolic.cosh(0.5)) ``` ### 修改日志 * 修复`classloader`引用错误。