├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jmeng │ │ └── luadroid │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jmengxy │ │ │ └── luadroid │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jmeng │ └── luadroid │ └── LuaDroidTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lualib ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── cpp │ ├── CMakeLists.txt │ ├── lua │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h │ └── luax.cpp │ ├── java │ └── com │ │ └── jmengxy │ │ └── lualib │ │ └── Lua.java │ └── res │ └── values │ └── values.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | .gradle/ 15 | build/ 16 | lualib/.externalNativeBuild/ 17 | app/.externalNativeBuild/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Eclipse project files 23 | .classpath 24 | .project 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Intellij project files 30 | *.iml 31 | *.ipr 32 | *.iws 33 | .idea/ 34 | 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | sudo: true 3 | android: 4 | components: 5 | # Uncomment the lines below if you want to 6 | # use the latest revision of Android SDK Tools 7 | - tools 8 | - platform-tools 9 | 10 | # The BuildTools version used by your project 11 | - build-tools-26.0.2 12 | 13 | # The SDK version used to compile your project 14 | - android-26 15 | - extra-google-m2repository 16 | - extra-android-m2repository 17 | addons: 18 | apt_packages: 19 | - pandoc 20 | artifacts: 21 | paths: 22 | - $(git ls-files -o | grep app/build/outputs | tr "\n" ":") 23 | 24 | before_install: 25 | - rm -fr $HOME/android-ndk-r14b 26 | - curl -L http://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip -O 27 | - unzip -oq android-ndk-r14b-linux-x86_64.zip 28 | - rm android-ndk-r14b-linux-x86_64.zip 29 | - export ANDROID_NDK_HOME=$HOME/android-ndk-r14b 30 | - export PATH=${ANDROID_NDK_HOME}:${PATH} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jie Meng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LuaDroid -- Lua interpreter for Android 2 | 3 | ## How to import LuaDroid into Android project 4 | 5 | 1. Add the JitPack repository to your build file 6 | - gradle 7 | 8 | Add it in your root build.gradle at the end of repositories: 9 | 10 | ``` 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | ``` 18 | 19 | - maven 20 | 21 | ``` 22 | 23 | 24 | jitpack.io 25 | https://jitpack.io 26 | 27 | 28 | ``` 29 | 30 | 2. Add the dependency 31 | - gradle 32 | 33 | ``` 34 | dependencies { 35 | compile 'com.github.jie-meng:LuaDroid:V1.0.0' 36 | } 37 | ``` 38 | 39 | - maven 40 | 41 | ``` 42 | 43 | com.github.jie-meng 44 | LuaDroid 45 | V1.0.0 46 | 47 | ``` 48 | 49 | ## Quick start 50 | 51 | ``` 52 | //create instance 53 | lua = new Lua(); 54 | 55 | //get 56 | String s = lua.getString("s", ""); 57 | int i = lua.getInteger("i", 0); 58 | double d = lua.getDouble("d", 0.0); 59 | boolean b = lua.getBoolean("b", false); 60 | 61 | //set 62 | lua.setString("s", "test_string"); 63 | lua.setInteger("i", 21); 64 | lua.setDouble("d", 3.14); 65 | lua.setBoolean("b", true); 66 | 67 | //others 68 | int type = lua.getType("s"); 69 | boolean b = lua.isInteger("i"); 70 | Pair result = lua.parseLine("s = string.lower('Text')"); 71 | Pair result = lua.parseFile("/home/user/test.lua"); 72 | 73 | //free resource 74 | lua.close(); 75 | ``` 76 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.jmengxy.luadroid" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildToolsVersion "26.0.2" 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_1_8 24 | targetCompatibility JavaVersion.VERSION_1_8 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(include: ['*.jar'], dir: 'libs') 30 | implementation project(':lualib') 31 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 32 | exclude group: 'com.android.support', module: 'support-annotations' 33 | }) 34 | implementation "com.android.support:appcompat-v7:$support_lib_version" 35 | implementation 'com.android.support.constraint:constraint-layout:1.0.1' 36 | testImplementation 'junit:junit:4.12' 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jiemeng/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jmeng/luadroid/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jmeng.luadroid; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.jmeng.luadroid", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/jmengxy/luadroid/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jmengxy.luadroid; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Pair; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.jmengxy.lualib.Lua; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | public static final String INPUT = "input"; 16 | public static final String OUTPUT = "output"; 17 | 18 | private EditText inputEdit; 19 | private EditText scriptEdit; 20 | private TextView outputText; 21 | private Button executeButton; 22 | 23 | private Lua lua; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | initUI(); 29 | initLua(); 30 | } 31 | 32 | private void initLua() { 33 | lua = new Lua(); 34 | executeButton.setOnClickListener(v -> { 35 | lua.setString(INPUT, inputEdit.getText().toString()); 36 | Pair result = lua.parseLine(scriptEdit.getText().toString()); 37 | if (result.first) { 38 | String outputStr = ""; 39 | switch (lua.getType(OUTPUT)) { 40 | case Lua.LUA_TYPE_NIL: 41 | outputStr = "nil"; 42 | break; 43 | case Lua.LUA_TYPE_NUMBER: 44 | outputStr = lua.isInteger(OUTPUT) 45 | ? Integer.toString(lua.getInteger(OUTPUT, 0)) 46 | : Double.toString(lua.getDouble(OUTPUT, 0.0)); 47 | break; 48 | case Lua.LUA_TYPE_BOOLEAN: 49 | outputStr = lua.getBoolean(OUTPUT, false) ? "true" : "false"; 50 | break; 51 | case Lua.LUA_TYPE_STRING: 52 | outputStr = lua.getString(OUTPUT, ""); 53 | break; 54 | default: 55 | outputStr = ""; 56 | break; 57 | } 58 | outputText.setText(outputStr); 59 | } else { 60 | outputText.setText(""); 61 | Toast.makeText(this, "Script parse failed!", Toast.LENGTH_SHORT).show(); 62 | } 63 | }); 64 | } 65 | 66 | private void initUI() { 67 | setContentView(R.layout.activity_main); 68 | inputEdit = (EditText)findViewById(R.id.input); 69 | scriptEdit = (EditText)findViewById(R.id.script); 70 | outputText = (TextView) findViewById(R.id.output); 71 | executeButton = (Button) findViewById(R.id.execute); 72 | } 73 | 74 | @Override 75 | protected void onDestroy() { 76 | if (lua != null) { 77 | lua.close(); 78 | lua = null; 79 | } 80 | super.onDestroy(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 10 | 14 | 18 | 22 | 26 | 30 |