├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── 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 │ │ │ │ ├── attr.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── colors.xml │ │ │ ├── color │ │ │ │ ├── s_app_color_blue_2.xml │ │ │ │ ├── s_app_color_gray.xml │ │ │ │ ├── s_btn_blue_bg.xml │ │ │ │ ├── s_btn_blue_border.xml │ │ │ │ ├── s_btn_blue_text.xml │ │ │ │ └── s_topbar_btn_color.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── s_radius_button_bg.xml │ │ │ │ ├── s_app_touch_fix_area_bg.xml │ │ │ │ ├── pager_layout_item_bg.xml │ │ │ │ ├── radius_button_bg.xml │ │ │ │ ├── radius_button_bg_pressed.xml │ │ │ │ ├── common_bg_with_radius_and_border.xml │ │ │ │ ├── tab_panel_bg.xml │ │ │ │ ├── ic_home_normal.xml │ │ │ │ ├── ic_home_select.xml │ │ │ │ ├── ic_setting_normal.xml │ │ │ │ └── ic_setting_select.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_main.xml │ │ │ │ ├── fragment_setting.xml │ │ │ │ └── fragment_home.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── reizx │ │ │ │ └── luaj │ │ │ │ ├── model │ │ │ │ ├── DBHelper.java │ │ │ │ ├── retrofit │ │ │ │ │ ├── RetrofitHelper.java │ │ │ │ │ └── api │ │ │ │ │ │ └── IpApi.java │ │ │ │ └── DataManager.java │ │ │ │ ├── component │ │ │ │ ├── LuajLog.java │ │ │ │ ├── ListReturn.java │ │ │ │ ├── LuajAppUtil.java │ │ │ │ ├── RxBus.java │ │ │ │ └── hyperbolic.java │ │ │ │ ├── presenter │ │ │ │ ├── common │ │ │ │ │ ├── IBasePresenter.java │ │ │ │ │ └── BasePresenterImpl.java │ │ │ │ ├── MainPresenter.java │ │ │ │ ├── MainActivityPresenter.java │ │ │ │ ├── SettingPresenter.java │ │ │ │ └── HomePresenter.java │ │ │ │ ├── di │ │ │ │ ├── scope │ │ │ │ │ ├── ActivityScope.java │ │ │ │ │ ├── ServiceScope.java │ │ │ │ │ └── FragmentScope.java │ │ │ │ ├── qualifier │ │ │ │ │ └── IpQualifier.java │ │ │ │ ├── component │ │ │ │ │ ├── ServiceComponent.java │ │ │ │ │ ├── ActivityComponent.java │ │ │ │ │ ├── AppComponent.java │ │ │ │ │ └── FragmentComponent.java │ │ │ │ └── module │ │ │ │ │ ├── AppModule.java │ │ │ │ │ ├── ServiceModule.java │ │ │ │ │ ├── ActivityModule.java │ │ │ │ │ └── FragmentModule.java │ │ │ │ ├── contract │ │ │ │ ├── MainContract.java │ │ │ │ ├── SettingContract.java │ │ │ │ ├── MainActivityContract.java │ │ │ │ └── HomeConstract.java │ │ │ │ ├── broadcast │ │ │ │ └── BootBroadcast.java │ │ │ │ ├── bean │ │ │ │ └── event │ │ │ │ │ ├── ChangeMainFragmentEvent.java │ │ │ │ │ ├── IpStatusEvent.java │ │ │ │ │ └── TipEvent.java │ │ │ │ ├── util │ │ │ │ ├── LuajUtil.java │ │ │ │ ├── RxUtil.java │ │ │ │ └── SSLSocketClient.java │ │ │ │ ├── constant │ │ │ │ └── Constants.java │ │ │ │ ├── view │ │ │ │ ├── common │ │ │ │ │ ├── BaseView.java │ │ │ │ │ └── BaseActivity.java │ │ │ │ ├── fragment │ │ │ │ │ ├── SettingFragment.java │ │ │ │ │ └── MainFragment.java │ │ │ │ └── MainActivity.java │ │ │ │ ├── app │ │ │ │ └── App.java │ │ │ │ └── service │ │ │ │ └── ForegroundService.java │ │ ├── aidl │ │ │ └── com │ │ │ │ └── reizx │ │ │ │ └── luaj │ │ │ │ └── IAndromedaInf.aidl │ │ ├── assets │ │ │ ├── SimpleExample.lua │ │ │ ├── hyperbolicapp.lua │ │ │ └── ListExample.lua │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── reizx │ │ │ └── luaj │ │ │ ├── ExampleUnitTest.java │ │ │ └── TimeUtilJTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── reizx │ │ └── luaj │ │ ├── TimeUtilTest.java │ │ └── ExampleInstrumentedTest.java └── build.gradle ├── luaj ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── org │ │ │ └── luaj │ │ │ └── vm2 │ │ │ ├── NonTableMetatable.java │ │ │ ├── compiler │ │ │ ├── IntPtr.java │ │ │ └── InstructionPtr.java │ │ │ ├── ast │ │ │ ├── Name.java │ │ │ ├── TableConstructor.java │ │ │ ├── Chunk.java │ │ │ ├── FuncBody.java │ │ │ ├── Block.java │ │ │ ├── ParList.java │ │ │ ├── SyntaxElement.java │ │ │ ├── FuncName.java │ │ │ ├── TableField.java │ │ │ ├── FuncArgs.java │ │ │ ├── Variable.java │ │ │ ├── NameScope.java │ │ │ ├── Str.java │ │ │ └── NameResolver.java │ │ │ ├── Upvaldesc.java │ │ │ ├── LocVars.java │ │ │ ├── Metatable.java │ │ │ ├── OrphanedThread.java │ │ │ ├── lib │ │ │ ├── ResourceFinder.java │ │ │ ├── ZeroArgFunction.java │ │ │ ├── jse │ │ │ │ ├── JavaInstance.java │ │ │ │ ├── JavaArray.java │ │ │ │ └── JavaMember.java │ │ │ ├── OneArgFunction.java │ │ │ ├── TwoArgFunction.java │ │ │ ├── ThreeArgFunction.java │ │ │ └── VarArgFunction.java │ │ │ ├── UpValue.java │ │ │ ├── luajc │ │ │ └── JavaLoader.java │ │ │ ├── LuaNumber.java │ │ │ ├── server │ │ │ └── Launcher.java │ │ │ ├── LuaFunction.java │ │ │ ├── LuaBoolean.java │ │ │ └── TailcallVarargs.java │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── luaj │ │ │ └── vm2 │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── org │ │ └── luaj │ │ └── vm2 │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── doc ├── README.md └── faq │ └── LIST-FAQ.md ├── UPDATE_LOG.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .gitattributes ├── gradle.properties ├── LICENSE ├── signing_config.gradle └── gradlew.bat /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /luaj/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':luaj' 2 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # LUAJ说明 2 | ## 教程 3 | * [使用例子]() 4 | 5 | ## FAQ 6 | * [关于JAVA端返回数组以及LUA端使用](faq/LIST-FAQ.md) -------------------------------------------------------------------------------- /UPDATE_LOG.md: -------------------------------------------------------------------------------- 1 | # 更新日志 2 | ## 2019年5月28日11:32:26 3 | * 增加对android环境的判断 4 | 5 | ## 2018年6月28日12:02:22 6 | * 修复软键盘自动弹出问题 -------------------------------------------------------------------------------- /luaj/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | luaj 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /luaj/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/model/DBHelper.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.model; 2 | 3 | /** 4 | * 数据库操作 5 | */ 6 | public class DBHelper { 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kigkrazy/luaj-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/model/retrofit/RetrofitHelper.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.model.retrofit; 2 | 3 | /** 4 | * Retrofit网络请求的 5 | */ 6 | public class RetrofitHelper { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | .idea -------------------------------------------------------------------------------- /app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/component/LuajLog.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.component; 2 | 3 | import com.reizx.luaj.util.LogUtil; 4 | 5 | public class LuajLog { 6 | public static void d(String msg) { 7 | LogUtil.d(msg); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 08 14:59:16 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/component/ListReturn.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.component; 2 | 3 | public class ListReturn { 4 | /** 5 | * 返回字符串数组 6 | * @return 7 | */ 8 | public static String[] getStringTest(){ 9 | return new String[]{"111", "222", "333"}; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_app_color_blue_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_app_color_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/s_radius_button_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/s_app_touch_fix_area_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/common/IBasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter.common; 2 | 3 | import com.reizx.luaj.view.common.BaseView; 4 | 5 | /** 6 | * 基础的presenter类 7 | * @param 8 | */ 9 | public interface IBasePresenter { 10 | void attachView(T view); 11 | 12 | void detachView(); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/scope/ActivityScope.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.scope; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Created by kigkrazy on 18-5-12. 11 | */ 12 | 13 | @Scope 14 | @Retention(RUNTIME) 15 | public @interface ActivityScope { 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/scope/ServiceScope.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.scope; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Created by kigkrazy on 18-5-12. 11 | */ 12 | 13 | @Scope 14 | @Retention(RUNTIME) 15 | public @interface ServiceScope { 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_btn_blue_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_btn_blue_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_btn_blue_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/contract/MainContract.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.contract; 2 | 3 | import com.reizx.luaj.presenter.common.IBasePresenter; 4 | import com.reizx.luaj.view.common.BaseView; 5 | 6 | public class MainContract { 7 | public interface View extends BaseView { 8 | 9 | } 10 | 11 | public interface Presenter extends IBasePresenter { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/scope/FragmentScope.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.scope; 2 | 3 | import java.lang.annotation.Retention; 4 | 5 | import javax.inject.Scope; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Created by kigkrazy on 18-5-12. 11 | */ 12 | 13 | 14 | @Scope 15 | @Retention(RUNTIME) 16 | public @interface FragmentScope { 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/qualifier/IpQualifier.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.qualifier; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | 6 | import javax.inject.Qualifier; 7 | 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | @Qualifier 11 | @Documented 12 | @Retention(RUNTIME) 13 | public @interface IpQualifier { 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/color/s_topbar_btn_color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pager_layout_item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # 添加git属性,将所有换行符都转为lf 2 | #* text eol=lf 3 | *.txt text eol=lf 4 | *.sh text eol=lf 5 | *.py text eol=lf 6 | *.java text eol=lf 7 | *.md text eol=lf 8 | *.xml text eol=lf 9 | *.html text eol=lf 10 | 11 | *.jpg -text 12 | *.jar -text 13 | *.aar -text 14 | *.apk -text 15 | *.rar -text 16 | *.zip -text 17 | *.png -text -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/contract/SettingContract.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.contract; 2 | 3 | import com.reizx.luaj.presenter.common.IBasePresenter; 4 | import com.reizx.luaj.view.common.BaseView; 5 | 6 | public class SettingContract { 7 | public interface View extends BaseView { 8 | void showIpStatus(String msg); 9 | } 10 | 11 | public interface Presenter extends IBasePresenter { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/model/retrofit/api/IpApi.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.model.retrofit.api; 2 | 3 | import io.reactivex.Flowable; 4 | import okhttp3.ResponseBody; 5 | import retrofit2.http.GET; 6 | 7 | public interface IpApi { 8 | String HOST = "http://2018.ip138.com/"; 9 | 10 | /** 11 | * 获取IP信息 12 | * @return 13 | */ 14 | @GET("/ic.asp") 15 | Flowable getCurrentIp(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/component/ServiceComponent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.component; 2 | 3 | import com.reizx.luaj.di.module.ServiceModule; 4 | import com.reizx.luaj.di.scope.ServiceScope; 5 | 6 | import dagger.Component; 7 | 8 | /** 9 | * Created by kigkrazy on 18-5-12. 10 | */ 11 | 12 | @ServiceScope 13 | @Component(dependencies = AppComponent.class, modules = ServiceModule.class) 14 | public interface ServiceComponent { 15 | } 16 | -------------------------------------------------------------------------------- /luaj/src/test/java/org/luaj/vm2/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.luaj.vm2; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/reizx/luaj/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/aidl/com/reizx/luaj/IAndromedaInf.aidl: -------------------------------------------------------------------------------- 1 | // IAndromedaInf.aidl 2 | package com.reizx.luaj; 3 | 4 | // Declare any non-default types here with import statements 5 | 6 | interface IAndromedaInf { 7 | /** 8 | * Demonstrates some basic types that you can use as parameters 9 | * and return values in AIDL. 10 | */ 11 | void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, 12 | double aDouble, String aString); 13 | 14 | void remoteCall(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/MainPresenter.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter; 2 | 3 | import com.reizx.luaj.contract.MainContract; 4 | import com.reizx.luaj.model.DataManager; 5 | import com.reizx.luaj.presenter.common.BasePresenterImpl; 6 | 7 | import javax.inject.Inject; 8 | 9 | public class MainPresenter extends BasePresenterImpl implements MainContract.Presenter { 10 | @Inject 11 | public MainPresenter(DataManager dm) { 12 | super(dm); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/assets/SimpleExample.lua: -------------------------------------------------------------------------------- 1 | --- 2 | --- 例子执行请执行rlua模块中AndroidTest的SimpleExample测试用例 3 | --- Generated by EmmyLua(https://github.com/EmmyLua) 4 | --- Created by kig. 5 | --- DateTime: 2018/3/6 17:34 6 | --- 7 | 8 | -- 引入类 9 | LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 10 | LuajAppUtil = luajava.bindClass("com.reizx.luaj.component.LuajAppUtil") --Log打印类 11 | 12 | -- 调用类的静态接口 13 | LuajLog:d("hello luaj...1") 14 | LuajLog:d("hello luaj...2") 15 | LuajLog:d("hello luaj...3") 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radius_button_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/broadcast/BootBroadcast.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.broadcast; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import com.reizx.luaj.util.LogUtil; 8 | 9 | /** 10 | * 开机启动广播 11 | */ 12 | public class BootBroadcast extends BroadcastReceiver { 13 | @Override 14 | public void onReceive(Context context, Intent intent) { 15 | LogUtil.dt(BootBroadcast.class.toString(),"receive BootBroadcast"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/radius_button_bg_pressed.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/bean/event/ChangeMainFragmentEvent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.bean.event; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | public class ChangeMainFragmentEvent { 6 | Fragment fragment; 7 | 8 | public ChangeMainFragmentEvent(Fragment fragment) { 9 | this.fragment = fragment; 10 | } 11 | 12 | public Fragment getFragment() { 13 | return fragment; 14 | } 15 | 16 | public void setFragment(Fragment fragment) { 17 | this.fragment = fragment; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/common_bg_with_radius_and_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/module/AppModule.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.module; 2 | 3 | import com.reizx.luaj.app.App; 4 | 5 | import javax.inject.Singleton; 6 | 7 | import dagger.Module; 8 | import dagger.Provides; 9 | 10 | /** 11 | * Created by kigkrazy on 18-5-12. 12 | */ 13 | 14 | @Module 15 | public class AppModule { 16 | private final App application; 17 | 18 | public AppModule(App application) { 19 | this.application = application; 20 | } 21 | 22 | @Provides 23 | @Singleton 24 | App provideApplicationContext() { 25 | return application; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LUAJ-ANDROID 3 | 4 | invoke执行文件 5 | invoke执行命令流 6 | 自定义luaj环境 7 | 数组返回值接口测试 8 | 获取IP 9 | Andromeda请求 10 | 当前IP: 11 | null 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/tab_panel_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/component/ActivityComponent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.component; 2 | 3 | import android.app.Activity; 4 | 5 | import com.reizx.luaj.di.module.ActivityModule; 6 | import com.reizx.luaj.di.scope.ActivityScope; 7 | import com.reizx.luaj.view.MainActivity; 8 | 9 | import dagger.Component; 10 | 11 | /** 12 | * Created by kigkrazy on 18-5-12. 13 | */ 14 | 15 | @ActivityScope 16 | @Component(dependencies = AppComponent.class, modules = ActivityModule.class) 17 | public interface ActivityComponent { 18 | Activity getActivity(); 19 | 20 | void inject(MainActivity mainActivity); 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/module/ServiceModule.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.module; 2 | 3 | import android.app.Service; 4 | 5 | 6 | import com.reizx.luaj.di.scope.ServiceScope; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | /** 12 | * Created by kigkrazy on 18-5-12. 13 | */ 14 | 15 | @Module 16 | public class ServiceModule { 17 | private Service service; 18 | 19 | public ServiceModule(Service service) { 20 | this.service= service; 21 | } 22 | 23 | @Provides 24 | @ServiceScope 25 | public Service provideService() { 26 | return service; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/component/AppComponent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.component; 2 | 3 | import com.reizx.luaj.app.App; 4 | import com.reizx.luaj.di.module.AppModule; 5 | import com.reizx.luaj.di.module.HttpModule; 6 | import com.reizx.luaj.model.DataManager; 7 | 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Component; 11 | 12 | /** 13 | * Created by kigkrazy on 18-5-12. 14 | */ 15 | 16 | @Singleton 17 | @Component(modules = {AppModule.class, HttpModule.class}) 18 | public interface AppComponent { 19 | App getContext(); // 提供App的Context 20 | 21 | DataManager getDataManager();//数据管理实例 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/module/ActivityModule.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.module; 2 | 3 | import android.app.Activity; 4 | 5 | import com.reizx.luaj.di.scope.ActivityScope; 6 | 7 | import dagger.Module; 8 | import dagger.Provides; 9 | 10 | /** 11 | * Created by kigkrazy on 18-5-12. 12 | */ 13 | 14 | @Module 15 | public class ActivityModule { 16 | private Activity activity; 17 | 18 | public ActivityModule(Activity activity) { 19 | this.activity= activity; 20 | } 21 | 22 | @Provides 23 | @ActivityScope 24 | public Activity provideActivity() { 25 | return activity; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/contract/MainActivityContract.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.contract; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | import com.reizx.luaj.presenter.common.IBasePresenter; 6 | import com.reizx.luaj.view.common.BaseView; 7 | 8 | public class MainActivityContract { 9 | public interface View extends BaseView { 10 | /** 11 | * 切换主fragment 12 | * @param fragment 13 | */ 14 | void startFragment(Fragment fragment); 15 | } 16 | 17 | public interface Presenter extends IBasePresenter { 18 | void checkVersion(String currentVersion); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/test/java/com/reizx/luaj/TimeUtilJTest.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj; 2 | 3 | import com.blankj.utilcode.util.TimeUtils; 4 | 5 | import org.junit.Test; 6 | 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.Locale; 10 | 11 | public class TimeUtilJTest { 12 | @Test 13 | public void timeTest() { 14 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); 15 | String nowString = sdf.format(new Date()); 16 | 17 | Date date = TimeUtils.string2Date("2018-07-27", sdf); 18 | 19 | TimeUtils.getFitTimeSpan("2018-07-23", "2018-07-25", sdf, 1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/reizx/luaj/TimeUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj; 2 | 3 | import android.support.test.runner.AndroidJUnit4; 4 | 5 | import com.blankj.utilcode.util.TimeUtils; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import java.text.SimpleDateFormat; 11 | import java.util.Date; 12 | import java.util.Locale; 13 | 14 | @RunWith(AndroidJUnit4.class) 15 | public class TimeUtilTest { 16 | @Test 17 | public void timeTest() { 18 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); 19 | String nowString = sdf.format(new Date()); 20 | 21 | //Date date = TimeUtils.string2Date("2018-") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/module/FragmentModule.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.module; 2 | 3 | import android.app.Activity; 4 | import android.support.v4.app.Fragment; 5 | 6 | import com.reizx.luaj.di.scope.FragmentScope; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | /** 12 | * Created by kigkrazy on 18-5-12. 13 | */ 14 | 15 | @Module 16 | public class FragmentModule { 17 | private Fragment fragment; 18 | 19 | public FragmentModule(Fragment fragment) { 20 | this.fragment = fragment; 21 | } 22 | 23 | @Provides 24 | @FragmentScope 25 | public Activity provideActivity() { 26 | return fragment.getActivity(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/util/LuajUtil.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.util; 2 | 3 | import org.luaj.vm2.Globals; 4 | import org.luaj.vm2.LuaValue; 5 | import org.luaj.vm2.lib.jse.JsePlatform; 6 | 7 | public class LuajUtil { 8 | public static Globals globals = JsePlatform.standardGlobals(); 9 | 10 | /** 11 | * 执行lua文件 12 | * @param path 13 | */ 14 | public static void execFile(String path) { 15 | try { 16 | LuaValue chunk = globals.loadfile(path); 17 | // Use any of the "call()" or "invoke()" functions directly on the chunk. 18 | chunk.invoke(); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | LogUtil.d("exec file "); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/bean/event/IpStatusEvent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.bean.event; 2 | 3 | /** 4 | * ip状态通知事件 5 | */ 6 | public class IpStatusEvent { 7 | private String timestamp; 8 | private String ipistatus; 9 | 10 | public IpStatusEvent(String timestamp, String ipistatus) { 11 | this.timestamp = timestamp; 12 | this.ipistatus = ipistatus; 13 | } 14 | 15 | public String getTimestamp() { 16 | return timestamp; 17 | } 18 | 19 | public void setTimestamp(String timestamp) { 20 | this.timestamp = timestamp; 21 | } 22 | 23 | public String getIpistatus() { 24 | return ipistatus; 25 | } 26 | 27 | public void setIpistatus(String ipistatus) { 28 | this.ipistatus = ipistatus; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/NonTableMetatable.java: -------------------------------------------------------------------------------- 1 | package org.luaj.vm2; 2 | 3 | import org.luaj.vm2.LuaTable.Slot; 4 | 5 | class NonTableMetatable implements Metatable { 6 | 7 | private final LuaValue value; 8 | 9 | public NonTableMetatable(LuaValue value) { 10 | this.value = value; 11 | } 12 | 13 | public boolean useWeakKeys() { 14 | return false; 15 | } 16 | 17 | public boolean useWeakValues() { 18 | return false; 19 | } 20 | 21 | public LuaValue toLuaValue() { 22 | return value; 23 | } 24 | 25 | public Slot entry(LuaValue key, LuaValue value) { 26 | return LuaTable.defaultEntry(key, value); 27 | } 28 | 29 | public LuaValue wrap(LuaValue value) { 30 | return value; 31 | } 32 | 33 | public LuaValue arrayget(LuaValue[] array, int index) { 34 | return array[index]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /luaj/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/di/component/FragmentComponent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.di.component; 2 | 3 | import android.app.Activity; 4 | 5 | import com.reizx.luaj.di.module.FragmentModule; 6 | import com.reizx.luaj.di.scope.FragmentScope; 7 | import com.reizx.luaj.view.fragment.HomeFragment; 8 | import com.reizx.luaj.view.fragment.MainFragment; 9 | import com.reizx.luaj.view.fragment.SettingFragment; 10 | 11 | import dagger.Component; 12 | 13 | /** 14 | * Created by kigkrazy on 18-5-12. 15 | */ 16 | 17 | @FragmentScope 18 | @Component(dependencies = AppComponent.class, modules = FragmentModule.class) 19 | public interface FragmentComponent { 20 | Activity getActivity(); 21 | 22 | void Inject(HomeFragment homeFragment); 23 | 24 | void Inject(SettingFragment settingFragment); 25 | 26 | void Inject(MainFragment settingFragment); 27 | } 28 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/reizx/luaj/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj; 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 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.reizx.asf", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /luaj/src/androidTest/java/org/luaj/vm2/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package org.luaj.vm2; 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 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("org.luaj.vm2.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/assets/hyperbolicapp.lua: -------------------------------------------------------------------------------- 1 | -- Sample luaj code to try loading and executing the 'hyperbolic' sample library 2 | -- 3 | -- The sample library source is in examples/jse/hyperbolic.java. 4 | -- For this sample to work, that source must be compiled, and the class must 5 | -- be on the class path. 6 | -- 7 | -- First load the library via require(). This will call the public constructor 8 | -- for the class named 'hyperbolic' if it exists, and then initialize the 9 | -- library by invoking LuaValue.call('hyperbolic') on that instance 10 | require 'hyperbolic' 11 | 12 | LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 13 | 14 | -- Test that the table is in the globals, and the functions exist. 15 | -- LuajLog:d('hyperbolic : '..hyperbolic) 16 | -- LuajLog:d('hyperbolic.sinh : '..hyperbolic.sinh) 17 | -- LuajLog:d('hyperbolic.cosh : '..hyperbolic.cosh) 18 | 19 | -- Try exercising the functions. 20 | LuajLog:d('sinh(0.5) : '..hyperbolic.sinh(0.5)) 21 | LuajLog:d('cosh(0.5) : '..hyperbolic.cosh(0.5)) -------------------------------------------------------------------------------- /app/src/main/assets/ListExample.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- JAVA层返回数组的测试用例 3 | -- Created by IntelliJ IDEA. 4 | -- User: kig 5 | -- Date: 2018/9/28 6 | -- Time: 18:27 7 | -- To change this template use File | Settings | File Templates. 8 | -- 9 | 10 | -- 引入类 11 | LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 12 | LuajAppUtil = luajava.bindClass("com.reizx.luaj.component.LuajAppUtil") --Log打印类 13 | ListReturn = luajava.bindClass("com.reizx.luaj.component.ListReturn") --Log打印类 14 | 15 | LuajLog:d("===========================================================") 16 | LuajLog:d("ListExample test") 17 | LuajLog:d("===========================================================") 18 | 19 | -- 获取数组格式的返回值 20 | local string_list = ListReturn:getStringTest() 21 | LuajLog:d("type of string_list type: "..type(string_list)) 22 | -- 获取数组长度 23 | LuajLog:d("type of string_list length: "..#string_list) 24 | -- 遍历数组 25 | LuajLog:d('show all element #1 ') 26 | for i=1, #string_list do 27 | LuajLog:d(string.format('string_list[%d] : '..string_list[i], i)) 28 | end 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 15 | 16 | 17 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 kigkrazy 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 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/contract/HomeConstract.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.contract; 2 | 3 | import android.content.Context; 4 | 5 | import com.reizx.luaj.presenter.common.IBasePresenter; 6 | import com.reizx.luaj.view.common.BaseView; 7 | 8 | /** 9 | * 主页的借口约定类 10 | */ 11 | public class HomeConstract { 12 | public interface View extends BaseView{ 13 | /** 14 | * 设置当前IP 15 | * @param ip 16 | */ 17 | public void setCurrentIp(String ip); 18 | } 19 | 20 | public interface Presenter extends IBasePresenter { 21 | /** 22 | * 开始zookeeper的前台服务 23 | */ 24 | void startZkService(Context context); 25 | 26 | /** 27 | * 开始zookeeper的前台服务 28 | */ 29 | void stopZkService(Context context); 30 | 31 | /** 32 | * 绑定zookeeper的服务(用于测试) 33 | */ 34 | void bindZkService(); 35 | 36 | /** 37 | * 请求zookeeper的接口(用于测试) 38 | */ 39 | void callHelloZkService(); 40 | 41 | /** 42 | * 从IP138接口请求,并且显示当前IP 43 | */ 44 | void showCurrentIp(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.constant; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.Environment; 5 | 6 | import com.reizx.luaj.app.App; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * 常量类 12 | * Created by kigkrazy on 18-5-11. 13 | */ 14 | 15 | public class Constants { 16 | //todo 此处可以存放一些常量 17 | //================= PATH ==================== 18 | public static final String PATH_DATA = App.getInstance().getCacheDir().getAbsolutePath() + File.separator + "data";//获取data文件夹 19 | public static final String PATH_CACHE = PATH_DATA + "/NetCache";//网络缓存文件夹 20 | public static final String LOG_DIR = PATH_DATA + "/log";//log文件夹 21 | public static final String PATH_SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + App.getInstance().getPackageName();//sd卡下以包名为名称的文件夹 22 | 23 | 24 | //===========================前台测试服务=========================== 25 | public final static String FORGROUND_SERVICE_ACTION = "com.reizx.asf.service.ForegroundService"; 26 | public final static String FORGROUND_SERVICE_TITILE = "前台服务"; 27 | public final static String FORGROUND_SERVICE_CONTENT_TEXT = "正在运行..."; 28 | public final static int FORGROUND_SERVICE_ID = 5; 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/view/common/BaseView.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.view.common; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; 6 | 7 | public interface BaseView { 8 | 9 | /** 10 | * 返回界面错误信息,并处理 11 | * @param msg 12 | */ 13 | void showErrorMsg(String msg); 14 | 15 | //======= State ======= 16 | 17 | /** 18 | * 界面显示出错时候处理 19 | * 例如: 20 | * 1. 界面加载失败 21 | * 2. 网络请求失败时候处理 22 | */ 23 | void stateError(); 24 | 25 | 26 | /** 27 | * 界面为空,时候处理 28 | */ 29 | void stateEmpty(); 30 | 31 | /** 32 | * 界面正在加载 33 | */ 34 | void stateLoading(); 35 | 36 | /** 37 | * 界面状态执行 38 | */ 39 | void stateMain(); 40 | 41 | /** 42 | * Toast msg 43 | */ 44 | void toast(String msg); 45 | 46 | /** 47 | * 显示提示 48 | * @param iconType QMUI的几种内置的图标类型, 不显示请置为 -1 49 | * @param tipWord 提示语 50 | */ 51 | void showTip(@QMUITipDialog.Builder.IconType int iconType, @NonNull String tipWord); 52 | 53 | 54 | /** 55 | * 显示提示 56 | * @param tipWord 提示语 57 | */ 58 | void showTip(@NonNull String tipWord); 59 | 60 | 61 | /** 62 | * 解除提示 63 | */ 64 | void dismissTip(); 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/MainActivityPresenter.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter; 2 | 3 | import com.reizx.luaj.bean.event.ChangeMainFragmentEvent; 4 | import com.reizx.luaj.component.RxBus; 5 | import com.reizx.luaj.contract.MainActivityContract; 6 | import com.reizx.luaj.model.DataManager; 7 | import com.reizx.luaj.presenter.common.BasePresenterImpl; 8 | 9 | import javax.inject.Inject; 10 | 11 | import io.reactivex.functions.Consumer; 12 | 13 | public class MainActivityPresenter extends BasePresenterImpl implements MainActivityContract.Presenter { 14 | @Inject 15 | public MainActivityPresenter(DataManager dm) { 16 | super(dm); 17 | } 18 | 19 | @Override 20 | public void checkVersion(String currentVersion) { 21 | 22 | } 23 | 24 | @Override 25 | public void registerEvent() { 26 | super.registerEvent(); 27 | 28 | //注册启动fragment事件 29 | addSubscribe(RxBus.getInstance().toFlowable(ChangeMainFragmentEvent.class).subscribe(new Consumer() { 30 | @Override 31 | public void accept(ChangeMainFragmentEvent changeMainFragmentEvent) throws Exception { 32 | view.startFragment(changeMainFragmentEvent.getFragment()); 33 | } 34 | })); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 49dp 4 | @dimen/qmui_content_spacing_horizontal 5 | 6 | 7 | 1px 8 | -1px 9 | 10 | 11 | 12 | 46dp 13 | 23dp 14 | 10dp 15 | 35dp 16 | 17 | 18 | 30dp 19 | 20 | 21 | 35dp 22 | 20dp 23 | 50dp 24 | 25 | 26 | 35dp 27 | 16sp 28 | 29 | 30 | 4dp 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/SettingPresenter.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter; 2 | 3 | import com.reizx.luaj.bean.event.IpStatusEvent; 4 | import com.reizx.luaj.component.RxBus; 5 | import com.reizx.luaj.contract.SettingContract; 6 | import com.reizx.luaj.model.DataManager; 7 | import com.reizx.luaj.presenter.common.BasePresenterImpl; 8 | 9 | import javax.inject.Inject; 10 | 11 | import io.reactivex.functions.Consumer; 12 | 13 | public class SettingPresenter extends BasePresenterImpl implements SettingContract.Presenter{ 14 | @Inject 15 | public SettingPresenter(DataManager dm) { 16 | super(dm); 17 | } 18 | 19 | /** 20 | * 注册事件 21 | */ 22 | @Override 23 | public void registerEvent() { 24 | super.registerEvent(); 25 | addSubscribe(RxBus.getInstance().toFlowable(IpStatusEvent.class) 26 | .subscribe(new Consumer() { 27 | @Override 28 | public void accept(IpStatusEvent ipStatusEvent) throws Exception { 29 | String msg = ipStatusEvent.getTimestamp() + "\n" + ipStatusEvent.getIpistatus(); 30 | view.showIpStatus(msg); 31 | } 32 | })); 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/model/DataManager.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.model; 2 | 3 | import com.reizx.luaj.model.retrofit.api.IpApi; 4 | 5 | import okhttp3.OkHttpClient; 6 | import retrofit2.Retrofit; 7 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 8 | import retrofit2.converter.gson.GsonConverterFactory; 9 | 10 | /** 11 | * 将所有的APP请求在此处统一管理 12 | */ 13 | public class DataManager { 14 | IpApi ipApi; 15 | 16 | public DataManager(Retrofit.Builder builder, OkHttpClient client) { 17 | createAllApi(builder, client);//生成所有API对象 18 | } 19 | 20 | public void createAllApi(Retrofit.Builder builder, OkHttpClient client) { 21 | // todo 此处添加所有需要的API 22 | ipApi = createRetrofit(builder, client, IpApi.HOST).create(IpApi.class);//ip情况请求接口 23 | } 24 | 25 | /** 26 | * 创建Retrofit 27 | * 28 | * @param builder 29 | * @param client 30 | * @param url 31 | * @return 32 | */ 33 | private Retrofit createRetrofit(Retrofit.Builder builder, OkHttpClient client, String url) { 34 | return builder 35 | .baseUrl(url) 36 | .client(client) 37 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 38 | .addConverterFactory(GsonConverterFactory.create()) 39 | .build(); 40 | } 41 | 42 | public IpApi getIpApi() { 43 | return ipApi; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/app/App.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.app; 2 | 3 | import android.app.Application; 4 | import android.util.Log; 5 | 6 | import com.blankj.utilcode.util.Utils; 7 | import com.elvishew.xlog.LogLevel; 8 | import com.reizx.luaj.di.component.AppComponent; 9 | import com.reizx.luaj.di.component.DaggerAppComponent; 10 | import com.reizx.luaj.di.module.AppModule; 11 | import com.reizx.luaj.di.module.HttpModule; 12 | 13 | import static com.reizx.luaj.util.LogUtil.initLog; 14 | import org.qiyi.video.svg.Andromeda; 15 | 16 | /** 17 | * j 18 | * Created by kigkrazy on 18-5-10. 19 | */ 20 | 21 | public class App extends Application { 22 | private static App app; 23 | private static AppComponent appComponent; 24 | 25 | @Override 26 | public void onCreate() { 27 | super.onCreate(); 28 | app = this; 29 | //初始化日志环境,设置全局 30 | 31 | Log.d("luaj-tag", "App onCreate..."); 32 | initLog("luaj-tag", LogLevel.ALL,null); 33 | Utils.init(this);//初始化AndroidUtilCode库 34 | Andromeda.init(app); 35 | } 36 | 37 | public static App getInstance() { 38 | return app; 39 | } 40 | 41 | public static AppComponent getAppComponent() { 42 | if (appComponent == null) { 43 | appComponent = DaggerAppComponent.builder() 44 | .appModule(new AppModule(app)) 45 | .httpModule(new HttpModule()) 46 | .build(); 47 | } 48 | return appComponent; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/compiler/IntPtr.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.compiler; 23 | 24 | public class IntPtr { 25 | int i; 26 | IntPtr() { 27 | } 28 | IntPtr(int value) { 29 | this.i = value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/Name.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | 25 | public class Name { 26 | public final String name; 27 | public Variable variable; 28 | public Name(String name) { 29 | this.name = name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /doc/faq/LIST-FAQ.md: -------------------------------------------------------------------------------- 1 | # 关于JAVA端返回数组以及LUA端使用 2 | 3 | ## 支持的数组返回形式 4 | 目前不支持`List`与`ArrayList`,只支持数组(String[])形式的返回值。 5 | 6 | ## 获取数组长度 7 | ```lua 8 | LuajLog:d("type of string_list length: "..#string_list) 9 | ``` 10 | 11 | ## 遍历数组 12 | 参考例子(ListReturnExample.lua) 13 | ```lua 14 | LuajLog:d('show all element #1 ') 15 | for i=1, #string_list do 16 | LuajLog:d(string.format('string_list[%d] : '..string_list[i], i)) 17 | end 18 | ``` 19 | ---------------------------------------------------------- 20 | 21 | `ListReturnExample.lua`内容如下: 22 | ```lua 23 | -- 24 | -- JAVA层返回数组的测试用例 25 | -- Created by IntelliJ IDEA. 26 | -- User: kig 27 | -- Date: 2018/9/28 28 | -- Time: 18:27 29 | -- To change this template use File | Settings | File Templates. 30 | -- 31 | 32 | -- 引入类 33 | LuajLog = luajava.bindClass("com.reizx.luaj.component.LuajLog") --Log打印类 34 | LuajAppUtil = luajava.bindClass("com.reizx.luaj.component.LuajAppUtil") --Log打印类 35 | ListReturn = luajava.bindClass("com.reizx.luaj.component.ListReturn") --Log打印类 36 | 37 | LuajLog:d("===========================================================") 38 | LuajLog:d("ListReturnExample test") 39 | LuajLog:d("===========================================================") 40 | 41 | -- 获取数组格式的返回值 42 | local string_list = ListReturn:getStringTest() 43 | LuajLog:d("type of string_list type: "..type(string_list)) 44 | -- 获取数组长度 45 | LuajLog:d("type of string_list length: "..#string_list) 46 | -- 遍历数组 47 | LuajLog:d('show all element #1 ') 48 | for i=1, #string_list do 49 | LuajLog:d(string.format('string_list[%d] : '..string_list[i], i)) 50 | end 51 | 52 | ``` -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/util/RxUtil.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.util; 2 | 3 | import io.reactivex.BackpressureStrategy; 4 | import io.reactivex.Flowable; 5 | import io.reactivex.FlowableEmitter; 6 | import io.reactivex.FlowableOnSubscribe; 7 | import io.reactivex.FlowableTransformer; 8 | import io.reactivex.android.schedulers.AndroidSchedulers; 9 | import io.reactivex.schedulers.Schedulers; 10 | 11 | /** 12 | * Created by codeest on 2016/8/3. 13 | */ 14 | public class RxUtil { 15 | 16 | /** 17 | * 统一线程处理 18 | * @param 19 | * @return 20 | */ 21 | public static FlowableTransformer rxSchedulerHelper() { //compose简化线程 22 | return new FlowableTransformer() { 23 | @Override 24 | public Flowable apply(Flowable observable) { 25 | return observable.subscribeOn(Schedulers.io()) 26 | .observeOn(AndroidSchedulers.mainThread()); 27 | } 28 | }; 29 | } 30 | 31 | /** 32 | * 生成Flowable 33 | * @param 34 | * @return 35 | */ 36 | public static Flowable createData(final T t) { 37 | return Flowable.create(new FlowableOnSubscribe() { 38 | @Override 39 | public void subscribe(FlowableEmitter emitter) throws Exception { 40 | try { 41 | emitter.onNext(t); 42 | emitter.onComplete(); 43 | } catch (Exception e) { 44 | emitter.onError(e); 45 | } 46 | } 47 | }, BackpressureStrategy.BUFFER); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/TableConstructor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.util.List; 25 | 26 | public class TableConstructor extends Exp { 27 | public List fields; 28 | 29 | public void accept(Visitor visitor) { 30 | visitor.visit(this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/Chunk.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | public class Chunk extends SyntaxElement { 25 | public final Block block; 26 | 27 | public Chunk(Block b) { 28 | this.block = b; 29 | } 30 | 31 | public void accept( Visitor visitor ) { 32 | visitor.visit( this ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/compiler/InstructionPtr.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.compiler; 23 | 24 | class InstructionPtr { 25 | final int[] code; 26 | final int idx; 27 | InstructionPtr(int[] code, int idx ) { 28 | this.code = code; 29 | this.idx = idx; 30 | } 31 | int get() { 32 | return code[idx]; 33 | } 34 | void set(int value) { 35 | code[idx] = value; 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_home_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_home_select.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | -------------------------------------------------------------------------------- /luaj/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 28 11 | versionCode 10 12 | versionName "3.0.4" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | lintOptions { 26 | abortOnError false 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | 33 | implementation 'com.android.support:appcompat-v7:28.0.0' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 37 | implementation 'io.apisense:rhino-android:1.0' 38 | // https://mvnrepository.com/artifact/org.apache.bcel/bcel 39 | api group: 'org.apache.bcel', name: 'bcel', version: '5.2' 40 | } 41 | 42 | // 上传jcenter的工具配置 43 | apply plugin: 'com.novoda.bintray-release' 44 | 45 | // 发布请执行: 46 | // gradlew clean build bintrayUpload -PbintrayUser=kigkrazy -PbintrayKey=${APIKey} -PdryRun=false 47 | publish { 48 | repoName = 'reizxutils' 49 | artifactId = 'luaj-android' 50 | groupId = 'com.reizx' 51 | userOrg = 'kigkrazy'//bintray用户名 52 | publishVersion = android.defaultConfig.versionName 53 | website = 'https://github.com/kigkrazy/luaj-android' 54 | desc = 'luaj for android'//描述,不重要 55 | } -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/component/LuajAppUtil.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.component; 2 | 3 | import com.blankj.utilcode.util.AppUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class LuajAppUtil { 9 | 10 | 11 | /** 12 | * 获取当前APP信息 13 | * 14 | * @param 15 | * @return 16 | */ 17 | public static AppUtils.AppInfo getAppInfo() { 18 | return AppUtils.getAppInfo(); 19 | } 20 | 21 | /** 22 | * 获取APP信息 23 | * 24 | * @param packageName 25 | * @return 26 | */ 27 | public static AppUtils.AppInfo getAppInfo(String packageName) { 28 | return AppUtils.getAppInfo(packageName); 29 | } 30 | 31 | 32 | /** 33 | * 获取APP信息 34 | * 35 | * @param packageName 36 | * @return 37 | */ 38 | public static List getAppInfo1(String packageName) { 39 | List result = new ArrayList<>(); 40 | result.add("xxx"); 41 | result.add("yyy"); 42 | result.add("zzz"); 43 | return result; 44 | } 45 | 46 | /** 47 | * 获取APP信息 48 | * 49 | * @param packageName 50 | * @return 51 | */ 52 | public static String[] getAppInfo2(String packageName) { 53 | return new String[]{"xxx", "222222"}; 54 | } 55 | 56 | /** 57 | * 获取APP信息 58 | * 59 | * @param packageName 60 | * @return 61 | */ 62 | public static int[] getAppInfo3(String packageName) { 63 | return new int[]{1, 2}; 64 | } 65 | 66 | /** 67 | * 获取所有APP列表信息 68 | * 69 | * @return 70 | */ 71 | public static List getAppInfos() { 72 | return AppUtils.getAppsInfo(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/bean/event/TipEvent.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.bean.event; 2 | 3 | import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; 4 | 5 | /** 6 | * Tip窗口信息事件,一般我们需要连续弹出TIP的时候才使用TipEvent进行弹窗处理,否则直接调用view中的showtip即可 7 | */ 8 | public class TipEvent { 9 | private String clazzName; 10 | private TipAction action; 11 | private int iconType; 12 | private String tipWord; 13 | 14 | /** 15 | * 构造Tip事件 16 | * @param clazzName 显示Tip的view的类名 17 | * @param action 行为,显示/销毁 18 | * @param iconType 图标类型, 当为-1的时候,不显示图标, 当为action为DISMISS时,没有作用 19 | * @param tipWord 提示语句, 当为action为DISMISS时,没有作用 20 | */ 21 | public TipEvent(String clazzName, TipAction action, int iconType, String tipWord) { 22 | this.clazzName = clazzName; 23 | this.action = action; 24 | this.iconType = iconType; 25 | this.tipWord = tipWord; 26 | } 27 | 28 | public enum TipAction { 29 | SHOW,//显示 30 | DISMISS//销毁 31 | } 32 | 33 | public String getClazzName() { 34 | return clazzName; 35 | } 36 | 37 | public void setClazzName(String clazzName) { 38 | this.clazzName = clazzName; 39 | } 40 | 41 | public int getIconType() { 42 | return iconType; 43 | } 44 | 45 | public void setIconType(int iconType) { 46 | this.iconType = iconType; 47 | } 48 | 49 | public String getTipWord() { 50 | return tipWord; 51 | } 52 | 53 | public void setTipWord(String tipWord) { 54 | this.tipWord = tipWord; 55 | } 56 | 57 | public TipAction getAction() { 58 | return action; 59 | } 60 | 61 | public void setAction(TipAction action) { 62 | this.action = action; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/FuncBody.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | public class FuncBody extends SyntaxElement { 25 | public ParList parlist; 26 | public Block block; 27 | public NameScope scope; 28 | 29 | public FuncBody(ParList parlist, Block block) { 30 | this.parlist = parlist!=null? parlist: ParList.EMPTY_PARLIST; 31 | this.block = block; 32 | } 33 | public void accept(Visitor visitor) { 34 | visitor.visit(this); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/Block.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class Block extends Stat { 28 | 29 | public List stats = new ArrayList(); 30 | public NameScope scope; 31 | 32 | public void add(Stat s) { 33 | if ( s == null ) 34 | return; 35 | stats.add(s); 36 | } 37 | 38 | public void accept(Visitor visitor) { 39 | visitor.visit(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 16 | 24 | 25 | 33 | 34 | 40 | 41 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/ParList.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class ParList extends SyntaxElement { 28 | public static final List EMPTY_NAMELIST = new ArrayList(); 29 | public static final ParList EMPTY_PARLIST = new ParList(EMPTY_NAMELIST,false); 30 | 31 | public final List names; 32 | public final boolean isvararg; 33 | 34 | public ParList(List names, boolean isvararg) { 35 | this.names = names; 36 | this.isvararg = isvararg; 37 | } 38 | 39 | public void accept(Visitor visitor) { 40 | visitor.visit(this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/Upvaldesc.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | public class Upvaldesc { 25 | 26 | /* upvalue name (for debug information) */ 27 | public LuaString name; 28 | 29 | /* whether it is in stack */ 30 | public final boolean instack; 31 | 32 | /* index of upvalue (in stack or in outer function's list) */ 33 | public final short idx; 34 | 35 | public Upvaldesc(LuaString name, boolean instack, int idx) { 36 | this.name = name; 37 | this.instack = instack; 38 | this.idx = (short) idx; 39 | } 40 | 41 | public String toString() { 42 | return idx + (instack? " instack ": " closed ") + String.valueOf(name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/SyntaxElement.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | /** Base class for syntax elements of the parse tree that appear in source files. 25 | * The LuaParser class will fill these values out during parsing for use in 26 | * syntax highlighting, for example. 27 | */ 28 | public class SyntaxElement { 29 | /** The line number on which the element begins. */ 30 | public int beginLine; 31 | 32 | /** The column at which the element begins. */ 33 | public short beginColumn; 34 | 35 | /** The line number on which the element ends. */ 36 | public int endLine; 37 | 38 | /** The column at which the element ends. */ 39 | public short endColumn; 40 | } 41 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/FuncName.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class FuncName extends SyntaxElement { 28 | // example: a.b.c.d:e 29 | 30 | // initial base name: "a" 31 | public final Name name; 32 | 33 | // intermediate field accesses: "b", "c", "d" 34 | public List dots; 35 | 36 | // optional final method name: "e" 37 | public String method; 38 | 39 | public FuncName( String name ) { 40 | this.name = new Name(name); 41 | } 42 | 43 | public void adddot(String dot) { 44 | if ( dots == null ) 45 | dots = new ArrayList(); 46 | dots.add(dot); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /signing_config.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * 如何使用本文件配置签名? 3 | * 1. 将本文件复制到项目的根目录 4 | * 5 | * 2. 在buildTypes的release引入本文件。如下: 6 | * buildTypes { 7 | * ... 8 | * release { 9 | * minifyEnabled false 10 | * apply from: project.rootProject.rootDir.absolutePath + "\\signing_config.gradle" //引入签名配置 11 | * } 12 | * ... 13 | * } 14 | * 15 | * 3. 在项目根目录创建文件"SignatureInfo.properties"文件。这个文件里面必须填写四个属性,即签名相关信息。如下: 16 | * storeFile=${JKS_PATH} //签名文件位置 17 | * storePassword=${STORE_PASSWORD} //保存密码 18 | * keyAlias=${KEY_ALIAS}//别名 19 | * keyPassword=${KEY_PASSWORD}//密码 20 | * 21 | * 上面文件的四个属性,正好等于签名文件的四个属性,根据实际情况往对应的位置填入相应的值。 22 | */ 23 | 24 | //签名配置 25 | android { 26 | signingConfigs { 27 | zues_signature { 28 | //加载资源 29 | File signatureInfoFile = project.rootProject.file('SignatureInfo.properties') 30 | if (!signatureInfoFile.exists()) { 31 | return 32 | } 33 | Properties properties = new Properties() 34 | InputStream inputStream = project.rootProject.file('SignatureInfo.properties').newDataInputStream() 35 | properties.load(inputStream) 36 | //读取字段 37 | def key_storeFile = properties.getProperty('storeFile') 38 | def key_storePassword = properties.getProperty('storePassword') 39 | 40 | def key_keyAlias = properties.getProperty('keyAlias') 41 | def key_keyPassword = properties.getProperty('keyPassword') 42 | 43 | storeFile file(key_storeFile) 44 | keyAlias key_keyAlias 45 | keyPassword key_keyPassword 46 | storePassword key_storePassword 47 | } 48 | } 49 | 50 | buildTypes { 51 | release { 52 | File signatureInfoFile = project.rootProject.file('SignatureInfo.properties') 53 | if (signatureInfoFile.exists()) { 54 | apply plugin: 'walle' 55 | signingConfig signingConfigs.zues_signature 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/util/SSLSocketClient.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.util; 2 | 3 | import java.security.SecureRandom; 4 | import java.security.cert.X509Certificate; 5 | 6 | import javax.net.ssl.HostnameVerifier; 7 | import javax.net.ssl.SSLContext; 8 | import javax.net.ssl.SSLSession; 9 | import javax.net.ssl.SSLSocketFactory; 10 | import javax.net.ssl.TrustManager; 11 | import javax.net.ssl.X509TrustManager; 12 | 13 | /** 14 | * 绕过HTTPS验证工具类 15 | */ 16 | public class SSLSocketClient { 17 | //获取这个SSLSocketFactory 18 | public static SSLSocketFactory getSSLSocketFactory() 19 | { 20 | try 21 | { 22 | SSLContext sslContext = SSLContext.getInstance("SSL"); 23 | sslContext.init(null, getTrustManager(), new SecureRandom()); 24 | return sslContext.getSocketFactory(); 25 | } 26 | catch (Exception e) 27 | { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | 32 | //获取TrustManager 33 | private static TrustManager[] getTrustManager() 34 | { 35 | TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() 36 | { 37 | @Override 38 | public void checkClientTrusted(X509Certificate[] chain, String authType) 39 | { 40 | } 41 | 42 | @Override 43 | public void checkServerTrusted(X509Certificate[] chain, String authType) 44 | { 45 | } 46 | 47 | @Override 48 | public X509Certificate[] getAcceptedIssuers() 49 | { 50 | return new X509Certificate[]{}; 51 | } 52 | }}; 53 | return trustAllCerts; 54 | } 55 | 56 | //获取HostnameVerifier 57 | public static HostnameVerifier getHostnameVerifier() 58 | { 59 | HostnameVerifier hostnameVerifier = new HostnameVerifier() 60 | { 61 | @Override 62 | public boolean verify(String s, SSLSession sslSession) 63 | { 64 | return true; 65 | } 66 | }; 67 | return hostnameVerifier; 68 | } 69 | } -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/TableField.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | public class TableField extends SyntaxElement { 25 | 26 | public final Exp index; 27 | public final String name; 28 | public final Exp rhs; 29 | 30 | public TableField(Exp index, String name, Exp rhs) { 31 | this.index = index; 32 | this.name = name; 33 | this.rhs = rhs; 34 | } 35 | 36 | public static TableField keyedField(Exp index, Exp rhs) { 37 | return new TableField(index, null, rhs); 38 | } 39 | 40 | public static TableField namedField(String name, Exp rhs) { 41 | return new TableField(null, name, rhs); 42 | } 43 | 44 | public static TableField listField(Exp rhs) { 45 | return new TableField(null, null, rhs); 46 | } 47 | 48 | public void accept(Visitor visitor) { 49 | visitor.visit(this); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/component/RxBus.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.component; 2 | 3 | import com.reizx.luaj.util.RxUtil; 4 | 5 | import io.reactivex.Flowable; 6 | import io.reactivex.disposables.Disposable; 7 | import io.reactivex.functions.Consumer; 8 | import io.reactivex.processors.FlowableProcessor; 9 | import io.reactivex.processors.PublishProcessor; 10 | 11 | /** 12 | * 与EventBus类似是一种用于Android的发布/订阅事件总线。它有很多优点:简化应用组件间的通信; 13 | * 解耦事件的发送者和接收者;避免复杂和容易出错的依赖和生命周期的问题;很快,专门为高性能优化过等等。 14 | * 15 | * Created by codeest on 2016/8/2. 16 | */ 17 | public class RxBus { 18 | private static RxBus rxBus;//单例主体 19 | // PublishSubject只会把在订阅发生的时间点之后来自原始Flowable的数据发射给观察者 20 | private final FlowableProcessor flowableProcessor = PublishProcessor.create().toSerialized();//主要的事件总线对象 21 | 22 | /** 23 | * 获取实例 24 | * 25 | * @return 26 | */ 27 | public static RxBus getInstance() { 28 | if (rxBus == null) 29 | rxBus = new RxBus(); 30 | return rxBus; 31 | } 32 | 33 | /** 34 | * 事件推送 35 | * @param o 36 | */ 37 | public void post(Object o) { 38 | flowableProcessor.onNext(o); 39 | } 40 | 41 | /** 42 | * 延迟事件推送 43 | * @param o 事件 44 | * @param millis 45 | */ 46 | public void postDelay(final Object o, final long millis) { 47 | new Thread(new Runnable() { 48 | @Override 49 | public void run() { 50 | try { 51 | Thread.sleep(millis); 52 | flowableProcessor.onNext(o); 53 | } catch (InterruptedException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | }).start(); 58 | } 59 | 60 | 61 | // 根据传递的 eventType 类型返回特定类型(eventType)的 被观察者 62 | public Flowable toFlowable(Class eventType) { 63 | return flowableProcessor.ofType(eventType); 64 | } 65 | 66 | // 封装默认订阅 67 | public Disposable toDefaultFlowable(Class eventType, Consumer act) { 68 | return flowableProcessor.ofType(eventType).compose(RxUtil.rxSchedulerHelper()).subscribe(act); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'org.qiyi.svg.plugin' 4 | 5 | android { 6 | compileSdkVersion 28 7 | defaultConfig { 8 | applicationId "com.reizx.luaj" 9 | minSdkVersion 19 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | apply from: project.rootProject.rootDir.absolutePath + File.separator +"signing_config.gradle"//设置签名 20 | } 21 | } 22 | 23 | lintOptions { 24 | abortOnError false 25 | disable 'InvalidPackage' 26 | } 27 | } 28 | 29 | configurations.all { 30 | resolutionStrategy { 31 | force "com.android.support:recyclerview-v7:$supportVersion" 32 | force "com.android.support:appcompat-v7:$supportVersion" 33 | force "com.android.support:design:$supportVersion" 34 | force "com.android.support:support-vector-drawable:$supportVersion" 35 | } 36 | } 37 | 38 | dependencies { 39 | implementation fileTree(include: ['*.jar'], dir: 'libs') 40 | //noinspection GradleCompatible 41 | implementation 'com.android.support:appcompat-v7:28.0.0' 42 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 43 | testImplementation 'junit:junit:4.12' 44 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 45 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 46 | //一些常用类库 47 | api 'com.reizx:andrutil:1.8.1' 48 | //qmui库,腾讯出品的UI库(https://github.com/QMUI/QMUI_Android) 49 | api 'com.qmuiteam:qmui:1.1.5' 50 | // butterknife库 一个用于UI注入的库 51 | implementation 'com.jakewharton:butterknife:8.8.1' 52 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 53 | //dagger2 54 | api 'com.google.dagger:dagger:2.4' 55 | annotationProcessor 'com.google.dagger:dagger-compiler:2.4' 56 | //Andromeda 57 | api 'org.qiyi.video.svg:core:1.1.8' 58 | implementation project(':luaj') 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #00A8E1 5 | #8000A8E1 6 | #c000A8E1 7 | 8 | #31BDF3 9 | #7F31BDF3 10 | #7F31BDF3 11 | 12 | #EF5362 13 | #FE6D4B 14 | #FFCF47 15 | #9FD661 16 | #3FD0AD 17 | #2BBDF3 18 | #5A9AEF 19 | #AC8FEF 20 | #EE85C1 21 | 22 | @color/qmui_config_color_gray_5 23 | 24 | #D4D6D8 25 | #ffffff 26 | @color/bar_divider 27 | 28 | 29 | @color/app_color_theme_2 30 | @color/app_color_theme_1 31 | #7FEF5362 32 | 33 | 34 | 35 | 36 | @color/app_color_theme_4 37 | @color/app_color_blue 38 | @color/app_color_theme_3 39 | 40 | 41 | 42 | 43 | 44 | #FFEBF9FF 45 | 46 | #ff99A0AA 47 | #ff00A8E1 48 | 49 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/LocVars.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | /** 25 | * Data class to hold debug information relating to local variables for a {@link Prototype} 26 | */ 27 | public class LocVars { 28 | /** The local variable name */ 29 | public LuaString varname; 30 | 31 | /** The instruction offset when the variable comes into scope */ 32 | public int startpc; 33 | 34 | /** The instruction offset when the variable goes out of scope */ 35 | public int endpc; 36 | 37 | /** 38 | * Construct a LocVars instance. 39 | * @param varname The local variable name 40 | * @param startpc The instruction offset when the variable comes into scope 41 | * @param endpc The instruction offset when the variable goes out of scope 42 | */ 43 | public LocVars(LuaString varname, int startpc, int endpc) { 44 | this.varname = varname; 45 | this.startpc = startpc; 46 | this.endpc = endpc; 47 | } 48 | 49 | public String tojstring() { 50 | return varname+" "+startpc+"-"+endpc; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/Metatable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | import org.luaj.vm2.LuaTable.Slot; 25 | 26 | /** 27 | * Provides operations that depend on the __mode key of the metatable. 28 | */ 29 | interface Metatable { 30 | 31 | /** Return whether or not this table's keys are weak. */ 32 | public boolean useWeakKeys(); 33 | 34 | /** Return whether or not this table's values are weak. */ 35 | public boolean useWeakValues(); 36 | 37 | /** Return this metatable as a LuaValue. */ 38 | public LuaValue toLuaValue(); 39 | 40 | /** Return an instance of Slot appropriate for the given key and value. */ 41 | public Slot entry( LuaValue key, LuaValue value ); 42 | 43 | /** Returns the given value wrapped in a weak reference if appropriate. */ 44 | public LuaValue wrap( LuaValue value ); 45 | 46 | /** 47 | * Returns the value at the given index in the array, or null if it is a weak reference that 48 | * has been dropped. 49 | */ 50 | public LuaValue arrayget(LuaValue[] array, int index); 51 | } 52 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/OrphanedThread.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | /** 25 | * {@link java.lang.Error} sublcass that indicates a lua thread that is no 26 | * longer referenced has been detected. 27 | *

28 | * The java thread in which this is thrown should correspond to a 29 | * {@link LuaThread} being used as a coroutine that could not possibly be 30 | * resumed again because there are no more references to the LuaThread with 31 | * which it is associated. Rather than locking up resources forever, this error 32 | * is thrown, and should fall through all the way to the thread's {@link Thread#run()} method. 33 | *

34 | * Java code mixed with the luaj vm should not catch this error because it may 35 | * occur when the coroutine is not running, so any processing done during error 36 | * handling could break the thread-safety of the application because other lua 37 | * processing could be going on in a different thread. 38 | */ 39 | public class OrphanedThread extends Error { 40 | 41 | public OrphanedThread() { 42 | super("orphaned thread"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/FuncArgs.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import org.luaj.vm2.LuaString; 28 | 29 | public class FuncArgs extends SyntaxElement { 30 | 31 | public final List exps; 32 | 33 | /** exp1,exp2... */ 34 | public static FuncArgs explist(List explist) { 35 | return new FuncArgs(explist); 36 | } 37 | 38 | /** {...} */ 39 | public static FuncArgs tableconstructor(TableConstructor table) { 40 | return new FuncArgs(table); 41 | } 42 | 43 | /** "mylib" */ 44 | public static FuncArgs string(LuaString string) { 45 | return new FuncArgs(string); 46 | } 47 | 48 | public FuncArgs(List exps) { 49 | this.exps = exps; 50 | } 51 | 52 | public FuncArgs(LuaString string) { 53 | this.exps = new ArrayList(); 54 | this.exps.add( Exp.constant(string) ); 55 | } 56 | 57 | public FuncArgs(TableConstructor table) { 58 | this.exps = new ArrayList(); 59 | this.exps.add( table ); 60 | } 61 | 62 | public void accept(Visitor visitor) { 63 | visitor.visit(this); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/ResourceFinder.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import java.io.InputStream; 25 | 26 | import org.luaj.vm2.Globals; 27 | 28 | /** 29 | * Interface for opening application resource files such as scripts sources. 30 | *

31 | * This is used by required to load files that are part of 32 | * the application, and implemented by BaseLib 33 | * for both the Jme and Jse platforms. 34 | *

35 | * The Jme version of base lib {@link BaseLib} 36 | * implements {@link Globals#finder} via {@link Class#getResourceAsStream(String)}, 37 | * while the Jse version {@link org.luaj.vm2.lib.jse.JseBaseLib} implements it using {@link java.io.File#File(String)}. 38 | *

39 | * The io library does not use this API for file manipulation. 40 | *

41 | * @see BaseLib 42 | * @see Globals#finder 43 | * @see org.luaj.vm2.lib.jse.JseBaseLib 44 | * @see org.luaj.vm2.lib.jme.JmePlatform 45 | * @see org.luaj.vm2.lib.jse.JsePlatform 46 | */ 47 | public interface ResourceFinder { 48 | 49 | /** 50 | * Try to open a file, or return null if not found. 51 | * 52 | * @see org.luaj.vm2.lib.BaseLib 53 | * @see org.luaj.vm2.lib.jse.JseBaseLib 54 | * 55 | * @param filename 56 | * @return InputStream, or null if not found. 57 | */ 58 | public InputStream findResource( String filename ); 59 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 16 | 25 | 26 | 35 | 36 | 45 | 46 | 55 | 56 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/Variable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | 26 | /** Variable is created lua name scopes, and is a named, lua variable that 27 | * either refers to a lua local, global, or upvalue storage location. 28 | */ 29 | public class Variable { 30 | 31 | /** The name as it appears in lua source code */ 32 | public final String name; 33 | 34 | /** The lua scope in which this variable is defined. */ 35 | public final NameScope definingScope; 36 | 37 | /** true if this variable is an upvalue */ 38 | public boolean isupvalue; 39 | 40 | /** true if there are assignments made to this variable */ 41 | public boolean hasassignments; 42 | 43 | /** When hasassignments == false, and the initial value is a constant, this is the initial value */ 44 | public LuaValue initialValue; 45 | 46 | /** Global is named variable not associated with a defining scope */ 47 | public Variable(String name) { 48 | this.name = name; 49 | this.definingScope = null; 50 | } 51 | public Variable(String name, NameScope definingScope) { 52 | /** Local variable is defined in a particular scope. */ 53 | this.name = name; 54 | this.definingScope = definingScope; 55 | } 56 | public boolean isLocal() { 57 | return this.definingScope != null; 58 | } 59 | public boolean isConstant() { 60 | return ! hasassignments && initialValue != null; 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/UpValue.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | 25 | /** Upvalue used with Closure formulation 26 | *

27 | * @see LuaClosure 28 | * @see Prototype 29 | */ 30 | public final class UpValue { 31 | 32 | LuaValue[] array; // initially the stack, becomes a holder 33 | int index; 34 | 35 | /** 36 | * Create an upvalue relative to a stack 37 | * @param stack the stack 38 | * @param index the index on the stack for the upvalue 39 | */ 40 | public UpValue( LuaValue[] stack, int index) { 41 | this.array = stack; 42 | this.index = index; 43 | } 44 | 45 | public String toString() { 46 | return index + "/" + array.length + " " + array[index]; 47 | } 48 | 49 | /** 50 | * Convert this upvalue to a Java String 51 | * @return the Java String for this upvalue. 52 | * @see LuaValue#tojstring() 53 | */ 54 | public String tojstring() { 55 | return array[index].tojstring(); 56 | } 57 | 58 | /** 59 | * Get the value of the upvalue 60 | * @return the {@link LuaValue} for this upvalue 61 | */ 62 | public final LuaValue getValue() { 63 | return array[index]; 64 | } 65 | 66 | /** 67 | * Set the value of the upvalue 68 | * @param value the {@link LuaValue} to set it to 69 | */ 70 | public final void setValue( LuaValue value ) { 71 | array[index] = value; 72 | } 73 | 74 | /** 75 | * Close this upvalue so it is no longer on the stack 76 | */ 77 | public final void close() { 78 | LuaValue[] old = array; 79 | array = new LuaValue[] { old[index] }; 80 | old[index] = null; 81 | index = 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/component/hyperbolic.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.component; 2 | 3 | import org.luaj.vm2.LuaValue; 4 | import org.luaj.vm2.lib.OneArgFunction; 5 | import org.luaj.vm2.lib.TwoArgFunction; 6 | 7 | /** 8 | * Sample library that can be called via luaj's require() implementation. 9 | * 10 | * This library, when loaded, creates a lua package called "hyperbolic" 11 | * which has two functions, "sinh()" and "cosh()". 12 | * 13 | * Because the class is in the default Java package, it can be called using 14 | * lua code such as: 15 | * 16 |

 {@code
17 |  * require 'hyperbolic'
18 |  * print('sinh',  hyperbolic.sinh)
19 |  * print('sinh(1.0)',  hyperbolic.sinh(1.0))
20 |  * }
21 | * 22 | * When require() loads the code, two things happen: 1) the public constructor 23 | * is called to construct a library instance, and 2) the instance is invoked 24 | * as a java call with no arguments. This invocation should be used to initialize 25 | * the library, and add any values to globals that are desired. 26 | */ 27 | public class hyperbolic extends TwoArgFunction { 28 | 29 | /** Public constructor. To be loaded via require(), the library class 30 | * must have a public constructor. 31 | */ 32 | public hyperbolic() {} 33 | 34 | /** The implementation of the TwoArgFunction interface. 35 | * This will be called once when the library is loaded via require(). 36 | * @param modname LuaString containing the name used in the call to require(). 37 | * @param env LuaValue containing the environment for this function. 38 | * @return Value that will be returned in the require() call. In this case, 39 | * it is the library itself. 40 | */ 41 | public LuaValue call(LuaValue modname, LuaValue env) { 42 | LuaValue library = tableOf(); 43 | library.set( "sinh", new sinh() ); 44 | library.set( "cosh", new cosh() ); 45 | env.set( "hyperbolic", library ); 46 | //todo 官方这个例子少了如下的注册函数 47 | env.get("package").get("loaded").set("hyperbolic", library); 48 | return library; 49 | } 50 | 51 | /* Each library function is coded as a specific LibFunction based on the 52 | * arguments it expects and returns. By using OneArgFunction, rather than 53 | * LibFunction directly, the number of arguments supplied will be coerced 54 | * to match what the implementation expects. */ 55 | 56 | /** Mathematical sinh function provided as a OneArgFunction. */ 57 | static class sinh extends OneArgFunction { 58 | public LuaValue call(LuaValue x) { 59 | return LuaValue.valueOf(Math.sinh(x.checkdouble())); 60 | } 61 | } 62 | 63 | /** Mathematical cosh function provided as a OneArgFunction. */ 64 | static class cosh extends OneArgFunction { 65 | public LuaValue call(LuaValue x) { 66 | return LuaValue.valueOf(Math.cosh(x.checkdouble())); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/luajc/JavaLoader.java: -------------------------------------------------------------------------------- 1 | package org.luaj.vm2.luajc; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.luaj.vm2.LuaFunction; 7 | import org.luaj.vm2.LuaValue; 8 | import org.luaj.vm2.Prototype; 9 | 10 | /******************************************************************************* 11 | * Copyright (c) 2010 Luaj.org. All rights reserved. 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | ******************************************************************************/ 31 | public class JavaLoader extends ClassLoader { 32 | 33 | private Map unloaded = new HashMap(); 34 | 35 | public JavaLoader() { 36 | } 37 | 38 | public LuaFunction load( Prototype p, String classname, String filename, LuaValue env ) { 39 | JavaGen jg = new JavaGen( p, classname, filename, false ); 40 | return load( jg, env ); 41 | } 42 | 43 | public LuaFunction load( JavaGen jg, LuaValue env ) { 44 | include( jg ); 45 | return load( jg.classname, env ); 46 | } 47 | 48 | public LuaFunction load(String classname, LuaValue env) { 49 | try { 50 | Class c = loadClass( classname ); 51 | LuaFunction v = (LuaFunction) c.newInstance(); 52 | v.initupvalue1(env); 53 | return v; 54 | } catch ( Exception e ) { 55 | e.printStackTrace(); 56 | throw new IllegalStateException("bad class gen: "+e); 57 | } 58 | } 59 | 60 | public void include( JavaGen jg ) { 61 | unloaded.put( jg.classname, jg.bytecode ); 62 | for ( int i=0, n=jg.inners!=null? jg.inners.length: 0; i 27 | * The main subclasses are {@link LuaInteger} which holds values that fit in a java int, 28 | * and {@link LuaDouble} which holds all other number values. 29 | * @see LuaInteger 30 | * @see LuaDouble 31 | * @see LuaValue 32 | * 33 | */ 34 | abstract 35 | public class LuaNumber extends LuaValue { 36 | 37 | /** Shared static metatable for all number values represented in lua. */ 38 | public static LuaValue s_metatable; 39 | 40 | public int type() { 41 | return TNUMBER; 42 | } 43 | 44 | public String typename() { 45 | return "number"; 46 | } 47 | 48 | public LuaNumber checknumber() { 49 | return this; 50 | } 51 | 52 | public LuaNumber checknumber(String errmsg) { 53 | return this; 54 | } 55 | 56 | public LuaNumber optnumber(LuaNumber defval) { 57 | return this; 58 | } 59 | 60 | public LuaValue tonumber() { 61 | return this; 62 | } 63 | 64 | public boolean isnumber() { 65 | return true; 66 | } 67 | 68 | public boolean isstring() { 69 | return true; 70 | } 71 | 72 | public LuaValue getmetatable() { 73 | return s_metatable; 74 | } 75 | 76 | public LuaValue concat(LuaValue rhs) { return rhs.concatTo(this); } 77 | public Buffer concat(Buffer rhs) { return rhs.concatTo(this); } 78 | public LuaValue concatTo(LuaNumber lhs) { return strvalue().concatTo(lhs.strvalue()); } 79 | public LuaValue concatTo(LuaString lhs) { return strvalue().concatTo(lhs); } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/ZeroArgFunction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | import org.luaj.vm2.Varargs; 26 | 27 | /** Abstract base class for Java function implementations that take no arguments and 28 | * return one value. 29 | *

30 | * Subclasses need only implement {@link LuaValue#call()} to complete this class, 31 | * simplifying development. 32 | * All other uses of {@link #call(LuaValue)}, {@link #invoke(Varargs)},etc, 33 | * are routed through this method by this class. 34 | *

35 | * If one or more arguments are required, or variable argument or variable return values, 36 | * then use one of the related function 37 | * {@link OneArgFunction}, {@link TwoArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}. 38 | *

39 | * See {@link LibFunction} for more information on implementation libraries and library functions. 40 | * @see #call() 41 | * @see LibFunction 42 | * @see OneArgFunction 43 | * @see TwoArgFunction 44 | * @see ThreeArgFunction 45 | * @see VarArgFunction 46 | */ 47 | abstract public class ZeroArgFunction extends LibFunction { 48 | 49 | abstract public LuaValue call(); 50 | 51 | /** Default constructor */ 52 | public ZeroArgFunction() { 53 | } 54 | 55 | public LuaValue call(LuaValue arg) { 56 | return call(); 57 | } 58 | 59 | public LuaValue call(LuaValue arg1, LuaValue arg2) { 60 | return call(); 61 | } 62 | 63 | public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { 64 | return call(); 65 | } 66 | 67 | public Varargs invoke(Varargs varargs) { 68 | return call(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/jse/JavaInstance.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib.jse; 23 | 24 | import java.lang.reflect.Field; 25 | 26 | import org.luaj.vm2.LuaError; 27 | import org.luaj.vm2.LuaUserdata; 28 | import org.luaj.vm2.LuaValue; 29 | 30 | /** 31 | * LuaValue that represents a Java instance. 32 | *

33 | * Will respond to get() and set() by returning field values or methods. 34 | *

35 | * This class is not used directly. 36 | * It is returned by calls to {@link CoerceJavaToLua#coerce(Object)} 37 | * when a subclass of Object is supplied. 38 | * @see CoerceJavaToLua 39 | * @see CoerceLuaToJava 40 | */ 41 | class JavaInstance extends LuaUserdata { 42 | 43 | JavaClass jclass; 44 | 45 | JavaInstance(Object instance) { 46 | super(instance); 47 | } 48 | 49 | public LuaValue get(LuaValue key) { 50 | if ( jclass == null ) 51 | jclass = JavaClass.forClass(m_instance.getClass()); 52 | Field f = jclass.getField(key); 53 | if ( f != null ) 54 | try { 55 | return CoerceJavaToLua.coerce(f.get(m_instance)); 56 | } catch (Exception e) { 57 | throw new LuaError(e); 58 | } 59 | LuaValue m = jclass.getMethod(key); 60 | if ( m != null ) 61 | return m; 62 | Class c = jclass.getInnerClass(key); 63 | if ( c != null ) 64 | return JavaClass.forClass(c); 65 | return super.get(key); 66 | } 67 | 68 | public void set(LuaValue key, LuaValue value) { 69 | if ( jclass == null ) 70 | jclass = JavaClass.forClass(m_instance.getClass()); 71 | Field f = jclass.getField(key); 72 | if ( f != null ) 73 | try { 74 | f.set(m_instance, CoerceLuaToJava.coerce(value, f.getType())); 75 | return; 76 | } catch (Exception e) { 77 | throw new LuaError(e); 78 | } 79 | super.set(key, value); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/OneArgFunction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | import org.luaj.vm2.Varargs; 26 | 27 | /** Abstract base class for Java function implementations that take one argument and 28 | * return one value. 29 | *

30 | * Subclasses need only implement {@link LuaValue#call(LuaValue)} to complete this class, 31 | * simplifying development. 32 | * All other uses of {@link #call()}, {@link #invoke(Varargs)},etc, 33 | * are routed through this method by this class, 34 | * dropping or extending arguments with {@code nil} values as required. 35 | *

36 | * If more than one argument are required, or no arguments are required, 37 | * or variable argument or variable return values, 38 | * then use one of the related function 39 | * {@link ZeroArgFunction}, {@link TwoArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}. 40 | *

41 | * See {@link LibFunction} for more information on implementation libraries and library functions. 42 | * @see #call(LuaValue) 43 | * @see LibFunction 44 | * @see ZeroArgFunction 45 | * @see TwoArgFunction 46 | * @see ThreeArgFunction 47 | * @see VarArgFunction 48 | */ 49 | abstract public class OneArgFunction extends LibFunction { 50 | 51 | abstract public LuaValue call(LuaValue arg); 52 | 53 | /** Default constructor */ 54 | public OneArgFunction() { 55 | } 56 | 57 | public final LuaValue call() { 58 | return call(NIL); 59 | } 60 | 61 | public final LuaValue call(LuaValue arg1, LuaValue arg2) { 62 | return call(arg1); 63 | } 64 | 65 | public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { 66 | return call(arg1); 67 | } 68 | 69 | public Varargs invoke(Varargs varargs) { 70 | return call(varargs.arg1()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/TwoArgFunction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | import org.luaj.vm2.Varargs; 26 | 27 | /** Abstract base class for Java function implementations that take two arguments and 28 | * return one value. 29 | *

30 | * Subclasses need only implement {@link LuaValue#call(LuaValue,LuaValue)} to complete this class, 31 | * simplifying development. 32 | * All other uses of {@link #call()}, {@link #invoke(Varargs)},etc, 33 | * are routed through this method by this class, 34 | * dropping or extending arguments with {@code nil} values as required. 35 | *

36 | * If more or less than two arguments are required, 37 | * or variable argument or variable return values, 38 | * then use one of the related function 39 | * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}. 40 | *

41 | * See {@link LibFunction} for more information on implementation libraries and library functions. 42 | * @see #call(LuaValue,LuaValue) 43 | * @see LibFunction 44 | * @see ZeroArgFunction 45 | * @see OneArgFunction 46 | * @see ThreeArgFunction 47 | * @see VarArgFunction 48 | */ 49 | abstract public class TwoArgFunction extends LibFunction { 50 | 51 | abstract public LuaValue call(LuaValue arg1, LuaValue arg2); 52 | 53 | /** Default constructor */ 54 | public TwoArgFunction() { 55 | } 56 | 57 | public final LuaValue call() { 58 | return call(NIL, NIL); 59 | } 60 | 61 | public final LuaValue call(LuaValue arg) { 62 | return call(arg, NIL); 63 | } 64 | 65 | public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { 66 | return call(arg1, arg2); 67 | } 68 | 69 | public Varargs invoke(Varargs varargs) { 70 | return call(varargs.arg1(),varargs.arg(2)); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/common/BasePresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter.common; 2 | 3 | import com.reizx.luaj.R; 4 | import com.reizx.luaj.bean.event.TipEvent; 5 | import com.reizx.luaj.component.RxBus; 6 | import com.reizx.luaj.model.DataManager; 7 | import com.reizx.luaj.view.common.BaseView; 8 | 9 | import io.reactivex.disposables.CompositeDisposable; 10 | import io.reactivex.disposables.Disposable; 11 | import io.reactivex.functions.Consumer; 12 | 13 | public class BasePresenterImpl implements IBasePresenter { 14 | protected T view; 15 | // CompositeDisposable是Disposable的容器,用来快速解除订阅,管理多个Disposable的生命周期 16 | public DataManager dm;// 数据管理 17 | 18 | protected CompositeDisposable compositeDisposable; 19 | 20 | public BasePresenterImpl(DataManager dm) { 21 | this.dm = dm; 22 | } 23 | 24 | /** 25 | * 解除订阅 26 | */ 27 | protected void unSubscribe() { 28 | if (compositeDisposable != null) { 29 | compositeDisposable.clear(); 30 | } 31 | } 32 | 33 | /** 34 | * 添加订阅 35 | * 36 | * @param subscription 37 | */ 38 | protected void addSubscribe(Disposable subscription) { 39 | if (compositeDisposable == null) { 40 | compositeDisposable = new CompositeDisposable(); 41 | } 42 | compositeDisposable.add(subscription); 43 | } 44 | 45 | /** 46 | * 增加订阅 47 | * 48 | * @param eventType 49 | * @param act 50 | * @param 51 | */ 52 | protected void addRxBusSubscribe(Class eventType, Consumer act) { 53 | if (compositeDisposable == null) { 54 | compositeDisposable = new CompositeDisposable(); 55 | } 56 | compositeDisposable.add(RxBus.getInstance().toDefaultFlowable(eventType, act)); 57 | } 58 | 59 | @Override 60 | public void attachView(T view) { 61 | this.view = view; 62 | registerEvent();//注册事件 63 | } 64 | 65 | @Override 66 | public void detachView() { 67 | this.view = null; 68 | unSubscribe(); 69 | } 70 | 71 | /** 72 | * 注册事件 73 | */ 74 | public void registerEvent(){ 75 | addSubscribe(RxBus.getInstance().toFlowable(TipEvent.class) 76 | .subscribe(new Consumer() { 77 | @Override 78 | public void accept(TipEvent tipEvent) throws Exception { 79 | if (!view.getClass().getName().equals(tipEvent.getClazzName())){ 80 | return; 81 | } 82 | 83 | if (tipEvent.getAction() == TipEvent.TipAction.DISMISS){ 84 | view.dismissTip(); 85 | return; 86 | } 87 | 88 | if (tipEvent.getIconType() == -1){ 89 | view.showTip(tipEvent.getTipWord()); 90 | return; 91 | } 92 | 93 | view.showTip(tipEvent.getIconType(), tipEvent.getTipWord()); 94 | } 95 | })); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/server/Launcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.server; 23 | 24 | import java.io.InputStream; 25 | import java.io.Reader; 26 | 27 | /** Interface to launch lua scripts using the {@link LuajClassLoader}. 28 | *

29 | * Note: This class is experimental and subject to change in future versions. 30 | *

31 | * This interface is purposely genericized to defer class loading so that 32 | * luaj classes can come from the class loader. 33 | *

34 | * The implementation should be acquired using {@link LuajClassLoader#NewLauncher()} 35 | * or {@link LuajClassLoader#NewLauncher(Class)} which ensure that the classes are 36 | * loaded to give each Launcher instance a pristine set of Globals, including 37 | * the shared metatables. 38 | * 39 | * @see LuajClassLoader 40 | * @see LuajClassLoader#NewLauncher() 41 | * @see LuajClassLoader#NewLauncher(Class) 42 | * @see DefaultLauncher 43 | * @since luaj 3.0.1 44 | */ 45 | public interface Launcher { 46 | 47 | /** Launch a script contained in a String. 48 | * 49 | * @param script The script contents. 50 | * @param arg Optional arguments supplied to the script. 51 | * @return return values from the script. 52 | */ 53 | public Object[] launch(String script, Object[] arg); 54 | 55 | /** Launch a script from an InputStream. 56 | * 57 | * @param script The script as an InputStream. 58 | * @param arg Optional arguments supplied to the script. 59 | * @return return values from the script. 60 | */ 61 | public Object[] launch(InputStream script, Object[] arg); 62 | 63 | /** Launch a script from a Reader. 64 | * 65 | * @param script The script as a Reader. 66 | * @param arg Optional arguments supplied to the script. 67 | * @return return values from the script. 68 | */ 69 | public Object[] launch(Reader script, Object[] arg); 70 | } -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/ThreeArgFunction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | import org.luaj.vm2.Varargs; 26 | 27 | /** Abstract base class for Java function implementations that take two arguments and 28 | * return one value. 29 | *

30 | * Subclasses need only implement {@link LuaValue#call(LuaValue,LuaValue,LuaValue)} to complete this class, 31 | * simplifying development. 32 | * All other uses of {@link #call()}, {@link #invoke(Varargs)},etc, 33 | * are routed through this method by this class, 34 | * dropping or extending arguments with {@code nil} values as required. 35 | *

36 | * If more or less than three arguments are required, 37 | * or variable argument or variable return values, 38 | * then use one of the related function 39 | * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link TwoArgFunction}, or {@link VarArgFunction}. 40 | *

41 | * See {@link LibFunction} for more information on implementation libraries and library functions. 42 | * @see #call(LuaValue,LuaValue,LuaValue) 43 | * @see LibFunction 44 | * @see ZeroArgFunction 45 | * @see OneArgFunction 46 | * @see TwoArgFunction 47 | * @see VarArgFunction 48 | */ 49 | abstract public class ThreeArgFunction extends LibFunction { 50 | 51 | abstract public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3); 52 | 53 | /** Default constructor */ 54 | public ThreeArgFunction() { 55 | } 56 | 57 | public final LuaValue call() { 58 | return call(NIL, NIL, NIL); 59 | } 60 | 61 | public final LuaValue call(LuaValue arg) { 62 | return call(arg, NIL, NIL); 63 | } 64 | 65 | public LuaValue call(LuaValue arg1, LuaValue arg2) { 66 | return call(arg1, arg2, NIL); 67 | } 68 | 69 | public Varargs invoke(Varargs varargs) { 70 | return call(varargs.arg1(),varargs.arg(2),varargs.arg(3)); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/jse/JavaArray.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib.jse; 23 | 24 | import java.lang.reflect.Array; 25 | 26 | import org.luaj.vm2.LuaTable; 27 | import org.luaj.vm2.LuaUserdata; 28 | import org.luaj.vm2.LuaValue; 29 | import org.luaj.vm2.lib.OneArgFunction; 30 | 31 | /** 32 | * LuaValue that represents a Java instance of array type. 33 | *

34 | * Can get elements by their integer key index, as well as the length. 35 | *

36 | * This class is not used directly. 37 | * It is returned by calls to {@link CoerceJavaToLua#coerce(Object)} 38 | * when an array is supplied. 39 | * @see CoerceJavaToLua 40 | * @see CoerceLuaToJava 41 | */ 42 | class JavaArray extends LuaUserdata { 43 | 44 | private static final class LenFunction extends OneArgFunction { 45 | public LuaValue call(LuaValue u) { 46 | return LuaValue.valueOf(Array.getLength(((LuaUserdata)u).m_instance)); 47 | } 48 | } 49 | 50 | static final LuaValue LENGTH = valueOf("length"); 51 | 52 | static final LuaTable array_metatable; 53 | static { 54 | array_metatable = new LuaTable(); 55 | array_metatable.rawset(LuaValue.LEN, new LenFunction()); 56 | } 57 | 58 | JavaArray(Object instance) { 59 | super(instance); 60 | setmetatable(array_metatable); 61 | } 62 | 63 | public LuaValue get(LuaValue key) { 64 | if ( key.equals(LENGTH) ) 65 | return valueOf(Array.getLength(m_instance)); 66 | if ( key.isint() ) { 67 | int i = key.toint() - 1; 68 | return i>=0 && i=0 && i 28 | * Direct subclass include {@link org.luaj.vm2.lib.LibFunction} 29 | * which is the base class for 30 | * all built-in library functions coded in Java, 31 | * and {@link LuaClosure}, which represents a lua closure 32 | * whose bytecode is interpreted when the function is invoked. 33 | * @see LuaValue 34 | * @see LuaClosure 35 | * @see org.luaj.vm2.lib.LibFunction 36 | */ 37 | abstract 38 | public class LuaFunction extends LuaValue { 39 | 40 | /** Shared static metatable for all functions and closures. */ 41 | public static LuaValue s_metatable; 42 | 43 | public int type() { 44 | return TFUNCTION; 45 | } 46 | 47 | public String typename() { 48 | return "function"; 49 | } 50 | 51 | public boolean isfunction() { 52 | return true; 53 | } 54 | 55 | public LuaFunction checkfunction() { 56 | return this; 57 | } 58 | 59 | public LuaFunction optfunction(LuaFunction defval) { 60 | return this; 61 | } 62 | 63 | public LuaValue getmetatable() { 64 | return s_metatable; 65 | } 66 | 67 | public String tojstring() { 68 | return "function: " + classnamestub(); 69 | } 70 | 71 | public LuaString strvalue() { 72 | return valueOf(tojstring()); 73 | } 74 | 75 | /** Return the last part of the class name, to be used as a function name in tojstring and elsewhere. 76 | * @return String naming the last part of the class name after the last dot (.) or dollar sign ($). 77 | */ 78 | public String classnamestub() { 79 | String s = getClass().getName(); 80 | return s.substring(Math.max(s.lastIndexOf('.'),s.lastIndexOf('$'))+1); 81 | } 82 | 83 | /** Return a human-readable name for this function. Returns the last part of the class name by default. 84 | * Is overridden by LuaClosure to return the source file and line, and by LibFunctions to return the name. 85 | * @return common name for this function. */ 86 | public String name() { 87 | return classnamestub(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/VarArgFunction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib; 23 | 24 | import org.luaj.vm2.LuaValue; 25 | import org.luaj.vm2.Varargs; 26 | 27 | /** Abstract base class for Java function implementations that takes varaiable arguments and 28 | * returns multiple return values. 29 | *

30 | * Subclasses need only implement {@link LuaValue#invoke(Varargs)} to complete this class, 31 | * simplifying development. 32 | * All other uses of {@link #call(LuaValue)}, {@link #invoke()},etc, 33 | * are routed through this method by this class, 34 | * converting arguments to {@link Varargs} and 35 | * dropping or extending return values with {@code nil} values as required. 36 | *

37 | * If between one and three arguments are required, and only one return value is returned, 38 | * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link TwoArgFunction}, or {@link ThreeArgFunction}. 39 | *

40 | * See {@link LibFunction} for more information on implementation libraries and library functions. 41 | * @see #invoke(Varargs) 42 | * @see LibFunction 43 | * @see ZeroArgFunction 44 | * @see OneArgFunction 45 | * @see TwoArgFunction 46 | * @see ThreeArgFunction 47 | */ 48 | abstract public class VarArgFunction extends LibFunction { 49 | 50 | public VarArgFunction() { 51 | } 52 | 53 | public LuaValue call() { 54 | return invoke(NONE).arg1(); 55 | } 56 | 57 | public LuaValue call(LuaValue arg) { 58 | return invoke(arg).arg1(); 59 | } 60 | 61 | public LuaValue call(LuaValue arg1, LuaValue arg2) { 62 | return invoke(varargsOf(arg1,arg2)).arg1(); 63 | } 64 | 65 | public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { 66 | return invoke(varargsOf(arg1,arg2,arg3)).arg1(); 67 | } 68 | 69 | /** 70 | * Subclass responsibility. 71 | * May not have expected behavior for tail calls. 72 | * Should not be used if: 73 | * - function has a possibility of returning a TailcallVarargs 74 | * @param args the arguments to the function call. 75 | */ 76 | public Varargs invoke(Varargs args) { 77 | return onInvoke(args).eval(); 78 | } 79 | 80 | public Varargs onInvoke(Varargs args) { 81 | return invoke(args); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/lib/jse/JavaMember.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.lib.jse; 23 | 24 | import org.luaj.vm2.Varargs; 25 | import org.luaj.vm2.lib.VarArgFunction; 26 | import org.luaj.vm2.lib.jse.CoerceLuaToJava.Coercion; 27 | 28 | /** 29 | * Java method or constructor. 30 | *

31 | * Primarily handles argument coercion for parameter lists including scoring of compatibility and 32 | * java varargs handling. 33 | *

34 | * This class is not used directly. 35 | * It is an abstract base class for {@link JavaConstructor} and {@link JavaMethod}. 36 | * @see JavaConstructor 37 | * @see JavaMethod 38 | * @see CoerceJavaToLua 39 | * @see CoerceLuaToJava 40 | */ 41 | abstract 42 | class JavaMember extends VarArgFunction { 43 | 44 | static final int METHOD_MODIFIERS_VARARGS = 0x80; 45 | 46 | final Coercion[] fixedargs; 47 | final Coercion varargs; 48 | 49 | protected JavaMember(Class[] params, int modifiers) { 50 | boolean isvarargs = ((modifiers & METHOD_MODIFIERS_VARARGS) != 0); 51 | fixedargs = new CoerceLuaToJava.Coercion[isvarargs? params.length-1: params.length]; 52 | for ( int i=0; ifixedargs.length? CoerceLuaToJava.SCORE_WRONG_TYPE * (n-fixedargs.length): 0; 60 | for ( int j=0; j LUA_KEYWORDS = new HashSet(); 33 | 34 | static { 35 | String[] k = new String[] { 36 | "and", "break", "do", "else", "elseif", "end", 37 | "false", "for", "function", "if", "in", "local", 38 | "nil", "not", "or", "repeat", "return", 39 | "then", "true", "until", "while" }; 40 | for ( int i=0; i namedVariables = new HashMap(); 45 | 46 | public final NameScope outerScope; 47 | 48 | public int functionNestingCount; 49 | 50 | /** Construct default names scope */ 51 | public NameScope() { 52 | this.outerScope = null; 53 | this.functionNestingCount = 0; 54 | } 55 | 56 | /** Construct name scope within another scope*/ 57 | public NameScope(NameScope outerScope) { 58 | this.outerScope = outerScope; 59 | this.functionNestingCount = outerScope!=null? outerScope.functionNestingCount: 0; 60 | } 61 | 62 | /** Look up a name. If it is a global name, then throw IllegalArgumentException. */ 63 | public Variable find( String name ) throws IllegalArgumentException { 64 | validateIsNotKeyword(name); 65 | for ( NameScope n = this; n!=null; n=n.outerScope ) 66 | if ( n.namedVariables.containsKey(name) ) 67 | return (Variable)n.namedVariables.get(name); 68 | Variable value = new Variable(name); 69 | this.namedVariables.put(name, value); 70 | return value; 71 | } 72 | 73 | /** Define a name in this scope. If it is a global name, then throw IllegalArgumentException. */ 74 | public Variable define( String name ) throws IllegalStateException, IllegalArgumentException { 75 | validateIsNotKeyword(name); 76 | Variable value = new Variable(name, this); 77 | this.namedVariables.put(name, value); 78 | return value; 79 | } 80 | 81 | private void validateIsNotKeyword(String name) { 82 | if ( LUA_KEYWORDS.contains(name) ) 83 | throw new IllegalArgumentException("name is a keyword: '"+name+"'"); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_setting_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_setting_select.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/view/fragment/SettingFragment.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.view.fragment; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.widget.TextView; 7 | 8 | import com.blankj.utilcode.util.ResourceUtils; 9 | import com.qmuiteam.qmui.widget.QMUITopBar; 10 | import com.reizx.luaj.R; 11 | import com.reizx.luaj.contract.SettingContract; 12 | import com.reizx.luaj.presenter.SettingPresenter; 13 | import com.reizx.luaj.util.LogUtil; 14 | import com.reizx.luaj.util.RxUtil; 15 | import com.reizx.luaj.view.common.BaseFragment; 16 | 17 | import org.luaj.vm2.Globals; 18 | import org.luaj.vm2.lib.jse.JsePlatform; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | import butterknife.BindView; 23 | import butterknife.OnClick; 24 | import io.reactivex.Flowable; 25 | import io.reactivex.disposables.Disposable; 26 | import io.reactivex.functions.Consumer; 27 | 28 | public class SettingFragment extends BaseFragment implements SettingContract.View { 29 | Globals globals; 30 | @BindView(R.id.topbar) 31 | QMUITopBar mTopBar; 32 | 33 | @BindView(R.id.tv_setting_page_show_ip_des) 34 | TextView tvIpStatus; 35 | Disposable ds; 36 | 37 | @SuppressLint("CheckResult") 38 | @OnClick(R.id.btn_setting_page_test) 39 | public void clickTest() { 40 | if (ds != null && !ds.isDisposed()) { 41 | LogUtil.d("dispose the subscribe..."); 42 | ds.dispose(); 43 | ds = null; 44 | return; 45 | } 46 | 47 | LogUtil.d("click setting page test"); 48 | ds = Flowable.interval(1, TimeUnit.SECONDS) 49 | .onBackpressureDrop() 50 | .compose(RxUtil.rxSchedulerHelper()) 51 | .subscribe(new Consumer() { 52 | @Override 53 | public void accept(Long aLong) throws Exception { 54 | LogUtil.d("the inter ... " + aLong); 55 | } 56 | }, new Consumer() { 57 | @Override 58 | public void accept(Throwable throwable) throws Exception { 59 | LogUtil.d("flow err : " + throwable); 60 | } 61 | }); 62 | } 63 | 64 | @OnClick(R.id.btn_setting_page_xlog) 65 | public void printXlog() { 66 | LogUtil.d("start exec ..."); 67 | String sc_path = "/sdcard/SimpleExample.lua"; 68 | boolean copyResult = ResourceUtils.copyFileFromAssets("SimpleExample.lua", sc_path); 69 | if (!copyResult){ 70 | LogUtil.d("copy script error ..."); 71 | } 72 | globals.loadfile(sc_path).invoke(); 73 | } 74 | 75 | @Override 76 | public void onCreate(@Nullable Bundle savedInstanceState) { 77 | super.onCreate(savedInstanceState); 78 | globals = JsePlatform.standardGlobals(); 79 | } 80 | 81 | @Override 82 | public int getFragmentLayoutID() { 83 | return R.layout.fragment_setting; 84 | } 85 | 86 | @Override 87 | public void initAllMembersView() { 88 | super.initAllMembersView(); 89 | initTopBar(); 90 | } 91 | 92 | @Override 93 | protected void initInject() { 94 | getFragmentComponent().Inject(this); 95 | } 96 | 97 | public void initTopBar() { 98 | mTopBar.setTitle("设置"); 99 | } 100 | 101 | @Override 102 | public void showIpStatus(String msg) { 103 | tvIpStatus.setText(msg); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/LuaBoolean.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | /** 25 | * Extension of {@link LuaValue} which can hold a Java boolean as its value. 26 | *

27 | * These instance are not instantiated directly by clients. 28 | * Instead, there are exactly twon instances of this class, 29 | * {@link LuaValue#TRUE} and {@link LuaValue#FALSE} 30 | * representing the lua values {@code true} and {@code false}. 31 | * The function {@link LuaValue#valueOf(boolean)} will always 32 | * return one of these two values. 33 | *

34 | * Any {@link LuaValue} can be converted to its equivalent 35 | * boolean representation using {@link LuaValue#toboolean()} 36 | *

37 | * @see LuaValue 38 | * @see LuaValue#valueOf(boolean) 39 | * @see LuaValue#TRUE 40 | * @see LuaValue#FALSE 41 | */ 42 | public final class LuaBoolean extends LuaValue { 43 | 44 | /** The singleton instance representing lua {@code true} */ 45 | static final LuaBoolean _TRUE = new LuaBoolean(true); 46 | 47 | /** The singleton instance representing lua {@code false} */ 48 | static final LuaBoolean _FALSE = new LuaBoolean(false); 49 | 50 | /** Shared static metatable for boolean values represented in lua. */ 51 | public static LuaValue s_metatable; 52 | 53 | /** The value of the boolean */ 54 | public final boolean v; 55 | 56 | LuaBoolean(boolean b) { 57 | this.v = b; 58 | } 59 | 60 | public int type() { 61 | return LuaValue.TBOOLEAN; 62 | } 63 | 64 | public String typename() { 65 | return "boolean"; 66 | } 67 | 68 | public boolean isboolean() { 69 | return true; 70 | } 71 | 72 | public LuaValue not() { 73 | return v ? FALSE : LuaValue.TRUE; 74 | } 75 | 76 | /** 77 | * Return the boolean value for this boolean 78 | * @return value as a Java boolean 79 | */ 80 | public boolean booleanValue() { 81 | return v; 82 | } 83 | 84 | public boolean toboolean() { 85 | return v; 86 | } 87 | 88 | public String tojstring() { 89 | return v ? "true" : "false"; 90 | } 91 | 92 | public boolean optboolean(boolean defval) { 93 | return this.v; 94 | } 95 | 96 | public boolean checkboolean() { 97 | return v; 98 | } 99 | 100 | public LuaValue getmetatable() { 101 | return s_metatable; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/view/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.view; 2 | 3 | import android.Manifest; 4 | import android.annotation.SuppressLint; 5 | import android.content.Context; 6 | import android.os.Build; 7 | import android.support.v4.app.Fragment; 8 | 9 | import com.qmuiteam.qmui.util.QMUIStatusBarHelper; 10 | import com.reizx.luaj.R; 11 | import com.reizx.luaj.contract.MainActivityContract; 12 | import com.reizx.luaj.presenter.MainActivityPresenter; 13 | import com.reizx.luaj.util.LogUtil; 14 | import com.reizx.luaj.view.common.BaseActivity; 15 | import com.reizx.luaj.view.fragment.MainFragment; 16 | import com.tbruyelle.rxpermissions2.Permission; 17 | import com.tbruyelle.rxpermissions2.RxPermissions; 18 | 19 | import io.reactivex.functions.Consumer; 20 | 21 | public class MainActivity extends BaseActivity implements MainActivityContract.View { 22 | @Override 23 | protected int getLayoutID() { 24 | return R.layout.activity_main; 25 | } 26 | 27 | @Override 28 | public void initAllMembersView() { 29 | super.initAllMembersView(); 30 | QMUIStatusBarHelper.setStatusBarDarkMode(this);//沉浸式状态栏 31 | MainFragment mainFragment = new MainFragment(); 32 | getSupportFragmentManager() 33 | .beginTransaction() 34 | .add(R.id.fragment_app_main, mainFragment) 35 | .commit(); 36 | } 37 | 38 | @Override 39 | protected void initInject() { 40 | getActivityComponent().inject(this); 41 | } 42 | 43 | 44 | @Override 45 | protected void onCreateFinish() { 46 | //super.onCreateFinish(); 47 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 48 | requestPermission(); 49 | } 50 | 51 | /** 52 | * 请求权限 53 | */ 54 | @SuppressLint("CheckResult") 55 | public void requestPermission() { 56 | RxPermissions rxPermission = new RxPermissions(this); 57 | rxPermission.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE, 58 | Manifest.permission.READ_PHONE_STATE, 59 | Manifest.permission.INSTALL_PACKAGES, 60 | Manifest.permission.ACCESS_WIFI_STATE, 61 | Manifest.permission.READ_PHONE_STATE, 62 | Manifest.permission.INTERNET).subscribe(new Consumer() { 63 | @Override 64 | public void accept(Permission permission) throws Exception { 65 | if (permission.granted) { 66 | // 用户已经同意该权限 67 | LogUtil.d(permission.name + " is granted."); 68 | } else if (permission.shouldShowRequestPermissionRationale) { 69 | // 用户拒绝了该权限,没有选中『不再询问』(Never ask again),那么下次再次启动时,还会提示请求权限的对话框 70 | LogUtil.d(permission.name + " is denied. More info should be provided."); 71 | } else { 72 | // 用户拒绝了该权限,并且选中『不再询问』 73 | LogUtil.d(permission.name + " is denied."); 74 | } 75 | } 76 | }); 77 | } 78 | 79 | /** 80 | * 切换主fragment 81 | * @param fragment 82 | */ 83 | @Override 84 | public void startFragment(Fragment fragment) { 85 | String tagName = fragment.getClass().getSimpleName(); 86 | getSupportFragmentManager() 87 | .beginTransaction() 88 | .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, 89 | R.anim.slide_in_left, R.anim.slide_out_right) 90 | .replace(R.id.fragment_app_main, fragment, tagName) 91 | .addToBackStack(tagName) 92 | .commit(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/TailcallVarargs.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010-2011 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2; 23 | 24 | /** 25 | * Subclass of {@link Varargs} that represents a lua tail call 26 | * in a Java library function execution environment. 27 | *

28 | * Since Java doesn't have direct support for tail calls, 29 | * any lua function whose {@link Prototype} contains the 30 | * {@link Lua#OP_TAILCALL} bytecode needs a mechanism 31 | * for tail calls when converting lua-bytecode to java-bytecode. 32 | *

33 | * The tail call holds the next function and arguments, 34 | * and the client a call to {@link #eval()} executes the function 35 | * repeatedly until the tail calls are completed. 36 | *

37 | * Normally, users of luaj need not concern themselves with the 38 | * details of this mechanism, as it is built into the core 39 | * execution framework. 40 | * @see Prototype 41 | * @see org.luaj.vm2.luajc.LuaJC 42 | */ 43 | public class TailcallVarargs extends Varargs { 44 | 45 | private LuaValue func; 46 | private Varargs args; 47 | private Varargs result; 48 | 49 | public TailcallVarargs(LuaValue f, Varargs args) { 50 | this.func = f; 51 | this.args = args; 52 | } 53 | 54 | public TailcallVarargs(LuaValue object, LuaValue methodname, Varargs args) { 55 | this.func = object.get(methodname); 56 | this.args = LuaValue.varargsOf(object, args); 57 | } 58 | 59 | public boolean isTailcall() { 60 | return true; 61 | } 62 | 63 | public Varargs eval() { 64 | while ( result == null ) { 65 | Varargs r = func.onInvoke(args); 66 | if (r.isTailcall()) { 67 | TailcallVarargs t = (TailcallVarargs) r; 68 | func = t.func; 69 | args = t.args; 70 | } 71 | else { 72 | result = r; 73 | func = null; 74 | args = null; 75 | } 76 | } 77 | return result; 78 | } 79 | 80 | public LuaValue arg( int i ) { 81 | if ( result == null ) 82 | eval(); 83 | return result.arg(i); 84 | } 85 | 86 | public LuaValue arg1() { 87 | if (result == null) 88 | eval(); 89 | return result.arg1(); 90 | } 91 | 92 | public int narg() { 93 | if (result == null) 94 | eval(); 95 | return result.narg(); 96 | } 97 | 98 | public Varargs subargs(int start) { 99 | if (result == null) 100 | eval(); 101 | return result.subargs(start); 102 | } 103 | } -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/view/fragment/MainFragment.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.view.fragment; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | import android.support.v4.content.ContextCompat; 7 | import android.support.v4.view.ViewPager; 8 | 9 | import com.qmuiteam.qmui.widget.QMUITabSegment; 10 | import com.reizx.luaj.R; 11 | import com.reizx.luaj.contract.MainContract; 12 | import com.reizx.luaj.presenter.MainPresenter; 13 | import com.reizx.luaj.view.common.BaseFragment; 14 | 15 | import java.util.HashMap; 16 | 17 | import butterknife.BindView; 18 | 19 | public class MainFragment extends BaseFragment implements MainContract.View { 20 | @BindView(R.id.pager) 21 | ViewPager mViewPager; 22 | @BindView(R.id.tabs) 23 | QMUITabSegment mTabs; 24 | private HashMap mPages = new HashMap(); 25 | 26 | @Override 27 | public int getFragmentLayoutID() { 28 | return R.layout.fragment_main; 29 | } 30 | 31 | @Override 32 | public void initAllMembersView() { 33 | initTabs();//初始化tab以及对应界面 34 | } 35 | 36 | @Override 37 | protected void initInject() { 38 | getFragmentComponent().Inject(this); 39 | } 40 | 41 | public void initTabs(){ 42 | QMUITabSegment.Tab homeTab = new QMUITabSegment.Tab( 43 | ContextCompat.getDrawable(getContext(), R.drawable.ic_home_normal), 44 | ContextCompat.getDrawable(getContext(), R.drawable.ic_home_select), 45 | "主页", false 46 | ); 47 | 48 | QMUITabSegment.Tab myTab = new QMUITabSegment.Tab( 49 | ContextCompat.getDrawable(getContext(), R.drawable.ic_setting_normal), 50 | ContextCompat.getDrawable(getContext(), R.drawable.ic_setting_select), 51 | "设置", false 52 | ); 53 | 54 | mTabs.addTab(homeTab) 55 | .addTab(myTab); 56 | 57 | //region 初始化ViewPage 58 | mPages.put(Pager.HOME, new HomeFragment()); 59 | mPages.put(Pager.SETTING, new SettingFragment()); 60 | MainPageAdapter mainPageAdapter = new MainPageAdapter(getChildFragmentManager(), mPages);//解决多层嵌套fragment,在fragment切换时候空白问题 61 | //MainPageAdapter mainPageAdapter = new MainPageAdapter(getFragmentManager(), mPages); 62 | mViewPager.setAdapter(mainPageAdapter); 63 | //endregion 64 | 65 | mTabs.setupWithViewPager(mViewPager, false); 66 | } 67 | 68 | 69 | /** 70 | * 配合ViewPage使用的适配器 71 | */ 72 | class MainPageAdapter extends FragmentPagerAdapter { 73 | HashMap mPages; 74 | public MainPageAdapter(FragmentManager fm, HashMap pages) { 75 | super(fm); 76 | this.mPages = pages; 77 | } 78 | 79 | @Override 80 | public Fragment getItem(int position) { 81 | return mPages.get(Pager.getPagerFromPositon(position)); 82 | } 83 | 84 | @Override 85 | public int getCount() { 86 | return mPages.size(); 87 | } 88 | } 89 | 90 | enum Pager { 91 | HOME, //home界面标识符 92 | SETTING;//设置界面标识符 93 | 94 | public static Pager getPagerFromPositon(int position) { 95 | switch (position) { 96 | case 0: 97 | return HOME; 98 | case 1: 99 | return SETTING; 100 | default: 101 | return HOME; 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/presenter/HomePresenter.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.presenter; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; 8 | import com.reizx.luaj.bean.event.TipEvent; 9 | import com.reizx.luaj.component.RxBus; 10 | import com.reizx.luaj.constant.Constants; 11 | import com.reizx.luaj.contract.HomeConstract; 12 | import com.reizx.luaj.bean.event.IpStatusEvent; 13 | import com.reizx.luaj.model.DataManager; 14 | import com.reizx.luaj.presenter.common.BasePresenterImpl; 15 | import com.reizx.luaj.service.ForegroundService; 16 | import com.reizx.luaj.util.LogUtil; 17 | import com.reizx.luaj.util.RxUtil; 18 | 19 | import javax.inject.Inject; 20 | 21 | import io.reactivex.functions.Consumer; 22 | import okhttp3.ResponseBody; 23 | 24 | public class HomePresenter extends BasePresenterImpl implements HomeConstract.Presenter{ 25 | @Inject 26 | public HomePresenter(DataManager dm) { 27 | super(dm); 28 | } 29 | 30 | /** 31 | * 启动ZK服务 32 | * @param context app的context 33 | */ 34 | @Override 35 | public void startZkService(Context context) { 36 | Intent intentZkService = new Intent(context, ForegroundService.class); 37 | intentZkService.setAction(Constants.FORGROUND_SERVICE_ACTION); 38 | context.startService(intentZkService); 39 | } 40 | 41 | @Override 42 | public void stopZkService(Context context) { 43 | Intent intentZkService = new Intent(context, ForegroundService.class); 44 | intentZkService.setAction(Constants.FORGROUND_SERVICE_ACTION); 45 | context.stopService(intentZkService); 46 | } 47 | 48 | @Override 49 | public void bindZkService() { 50 | 51 | } 52 | 53 | @Override 54 | public void callHelloZkService() { 55 | 56 | } 57 | 58 | @SuppressLint("CheckResult") 59 | @Override 60 | public void showCurrentIp() { 61 | //view.setCurrentIp(); 62 | LogUtil.d("showCurrentIp..."); 63 | //view.showTip(QMUITipDialog.Builder.ICON_TYPE_LOADING, "正在请求"); 64 | RxBus.getInstance().post(new TipEvent(view.getClass().getName(), TipEvent.TipAction.SHOW, QMUITipDialog.Builder.ICON_TYPE_LOADING, "正在请求")); 65 | dm.getIpApi().getCurrentIp() 66 | .compose(RxUtil.rxSchedulerHelper()) 67 | .subscribe(new Consumer() { 68 | @Override 69 | public void accept(ResponseBody responseBody) throws Exception { 70 | String result = new String(responseBody.bytes(), "GB2312"); 71 | //todo 此处显示第二个TIP 72 | RxBus.getInstance().post(new TipEvent(view.getClass().getName(), TipEvent.TipAction.DISMISS, -1, null)); 73 | RxBus.getInstance().postDelay(new TipEvent(view.getClass().getName(), TipEvent.TipAction.DISMISS, -1, null), 5000);//销毁前一个TIP 74 | RxBus.getInstance().post(new TipEvent(view.getClass().getName(), TipEvent.TipAction.SHOW, QMUITipDialog.Builder.ICON_TYPE_SUCCESS, "请求成功"));//生成新TIP 75 | RxBus.getInstance().postDelay(new TipEvent(view.getClass().getName(), TipEvent.TipAction.DISMISS, -1, null), 500);//延迟销毁TIP 76 | view.setCurrentIp(result); 77 | String timestamp = "" + System.currentTimeMillis(); 78 | RxBus.getInstance().post(new IpStatusEvent(timestamp, result)); 79 | } 80 | }); 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/Str.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2010 Luaj.org. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | ******************************************************************************/ 22 | package org.luaj.vm2.ast; 23 | 24 | import java.io.ByteArrayOutputStream; 25 | import java.io.UnsupportedEncodingException; 26 | 27 | import org.luaj.vm2.LuaString; 28 | 29 | public class Str { 30 | 31 | private Str() {} 32 | 33 | public static LuaString quoteString(String image) { 34 | String s = image.substring(1, image.length()-1); 35 | byte[] bytes = unquote(s); 36 | return LuaString.valueUsing(bytes); 37 | } 38 | 39 | public static LuaString charString(String image) { 40 | String s = image.substring(1, image.length()-1); 41 | byte[] bytes = unquote(s); 42 | return LuaString.valueUsing(bytes); 43 | } 44 | 45 | public static LuaString longString(String image) { 46 | int i = image.indexOf('[', image.indexOf('[')+1)+1; 47 | String s = image.substring(i,image.length()-i); 48 | byte[] b = iso88591bytes(s); 49 | return LuaString.valueUsing(b); 50 | } 51 | 52 | public static byte[] iso88591bytes( String s ) { 53 | try { 54 | return s.getBytes("ISO8859-1"); 55 | } catch (UnsupportedEncodingException e) { 56 | throw new IllegalStateException("ISO8859-1 not supported"); 57 | } 58 | } 59 | 60 | public static byte[] unquote(String s) { 61 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 62 | char[] c = s.toCharArray(); 63 | int n = c.length; 64 | for ( int i=0; i='0' && c[i]<='9'; i++, j++ ) 71 | d = d * 10 + (int) (c[i]-'0'); 72 | baos.write( (byte) d ); 73 | --i; 74 | continue; 75 | case 'a': baos.write( (byte) 7 ); continue; 76 | case 'b': baos.write( (byte) '\b' ); continue; 77 | case 'f': baos.write( (byte) '\f' ); continue; 78 | case 'n': baos.write( (byte) '\n' ); continue; 79 | case 'r': baos.write( (byte) '\r' ); continue; 80 | case 't': baos.write( (byte) '\t' ); continue; 81 | case 'v': baos.write( (byte) 11 ); continue; 82 | case '"': baos.write( (byte) '"' ); continue; 83 | case '\'': baos.write( (byte) '\'' ); continue; 84 | case '\\': baos.write( (byte) '\\' ); continue; 85 | default: baos.write( (byte) c[i] ); break; 86 | } 87 | } else { 88 | baos.write( (byte) c[i] ); 89 | } 90 | } 91 | return baos.toByteArray(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /luaj/src/main/java/org/luaj/vm2/ast/NameResolver.java: -------------------------------------------------------------------------------- 1 | package org.luaj.vm2.ast; 2 | 3 | import java.util.List; 4 | 5 | import org.luaj.vm2.LuaValue; 6 | import org.luaj.vm2.ast.Exp.Constant; 7 | import org.luaj.vm2.ast.Exp.NameExp; 8 | import org.luaj.vm2.ast.Exp.VarExp; 9 | import org.luaj.vm2.ast.Stat.Assign; 10 | import org.luaj.vm2.ast.Stat.FuncDef; 11 | import org.luaj.vm2.ast.Stat.GenericFor; 12 | import org.luaj.vm2.ast.Stat.LocalAssign; 13 | import org.luaj.vm2.ast.Stat.LocalFuncDef; 14 | import org.luaj.vm2.ast.Stat.NumericFor; 15 | 16 | /** 17 | * Visitor that resolves names to scopes. 18 | * Each Name is resolved to a NamedVarible, possibly in a NameScope 19 | * if it is a local, or in no named scope if it is a global. 20 | */ 21 | public class NameResolver extends Visitor { 22 | 23 | private NameScope scope = null; 24 | 25 | private void pushScope() { 26 | scope = new NameScope(scope); 27 | } 28 | private void popScope() { 29 | scope = scope.outerScope; 30 | } 31 | 32 | public void visit(NameScope scope) { 33 | } 34 | 35 | public void visit(Block block) { 36 | pushScope(); 37 | block.scope = scope; 38 | super.visit(block); 39 | popScope(); 40 | } 41 | 42 | public void visit(FuncBody body) { 43 | pushScope(); 44 | scope.functionNestingCount++; 45 | body.scope = scope; 46 | super.visit(body); 47 | popScope(); 48 | } 49 | 50 | public void visit(LocalFuncDef stat) { 51 | defineLocalVar(stat.name); 52 | super.visit(stat); 53 | } 54 | 55 | public void visit(NumericFor stat) { 56 | pushScope(); 57 | stat.scope = scope; 58 | defineLocalVar(stat.name); 59 | super.visit(stat); 60 | popScope(); 61 | } 62 | 63 | public void visit(GenericFor stat) { 64 | pushScope(); 65 | stat.scope = scope; 66 | defineLocalVars( stat.names ); 67 | super.visit(stat); 68 | popScope(); 69 | } 70 | 71 | public void visit(NameExp exp) { 72 | exp.name.variable = resolveNameReference(exp.name); 73 | super.visit(exp); 74 | } 75 | 76 | public void visit(FuncDef stat) { 77 | stat.name.name.variable = resolveNameReference(stat.name.name); 78 | stat.name.name.variable.hasassignments = true; 79 | super.visit(stat); 80 | } 81 | 82 | public void visit(Assign stat) { 83 | super.visit(stat); 84 | for ( int i=0, n=stat.vars.size(); i0 && m names) { 113 | for ( int i=0, n=names.size(); ionStartCommand: "); 37 | //启动前台服务 38 | setNotification(Constants.FORGROUND_SERVICE_TITILE, 39 | Constants.FORGROUND_SERVICE_CONTENT_TEXT, 40 | R.mipmap.ic_launcher, 41 | R.mipmap.ic_launcher, 42 | Constants.FORGROUND_SERVICE_ID); 43 | //notificationManager.notify(1, notification); 44 | registerAndromeda(); 45 | return super.onStartCommand(intent, flags, startId); 46 | } 47 | 48 | @Override 49 | public void onDestroy() { 50 | super.onDestroy(); 51 | } 52 | 53 | 54 | public void setNotification(String title, String description, int smallIcon, int bigIcon, int forgroundServiceId) { 55 | // 在API11之后构建Notification的方式 56 | //NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 57 | Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); //获取一个Notification构造器 58 | builder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), bigIcon)) // 设置下拉列表中的图标(大图标) 59 | .setContentTitle(title) // 设置下拉列表里的标题 60 | .setSmallIcon(smallIcon) // 设置状态栏内的小图标 61 | .setContentText(description) // 设置描述 62 | .setWhen(System.currentTimeMillis()); // 设置该通知发生的时间 63 | 64 | //设置广播通知 65 | builder.setContentIntent(PendingIntent.getBroadcast(this, 1011, new Intent(this, NotificationClickReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); 66 | Notification notification = builder.build(); // 获取构建好的Notification 67 | notification.defaults = Notification.DEFAULT_SOUND; //设置为默认的声音 68 | startForeground(forgroundServiceId, notification); 69 | //notificationManager.notify(1, notification); 70 | } 71 | 72 | public void registerAndromeda() { 73 | Andromeda.registerRemoteService(IAndromedaInf.class, new IAndromedaInf.Stub() { 74 | @Override 75 | public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException { 76 | 77 | } 78 | 79 | @Override 80 | public void remoteCall() throws RemoteException { 81 | LogUtil.d("remoteCall success..."); 82 | } 83 | }); 84 | } 85 | 86 | /** 87 | * 前台服务广播接收器 88 | */ 89 | public static class NotificationClickReceiver extends BroadcastReceiver { 90 | @Override 91 | public void onReceive(Context context, Intent intent) { 92 | LogUtil.dt(TAG, "NotificationClickReceiver --------->onReceive: stop service"); 93 | context.stopService(new Intent(context, ForegroundService.class)); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/reizx/luaj/view/common/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.reizx.luaj.view.common; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | 9 | import com.blankj.utilcode.util.ToastUtils; 10 | import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; 11 | import com.reizx.luaj.app.App; 12 | import com.reizx.luaj.di.component.ActivityComponent; 13 | import com.reizx.luaj.di.component.DaggerActivityComponent; 14 | import com.reizx.luaj.di.module.ActivityModule; 15 | import com.reizx.luaj.presenter.common.IBasePresenter; 16 | 17 | import javax.inject.Inject; 18 | 19 | import butterknife.ButterKnife; 20 | 21 | /** 22 | * Created by Kigkrazy on 2017/7/19. 23 | */ 24 | 25 | public abstract class BaseActivity extends AppCompatActivity implements BaseView { 26 | protected Activity activity;//当前Activity的上下文 27 | QMUITipDialog tipDialog; 28 | 29 | @Inject 30 | protected T presenter; 31 | 32 | @Inject 33 | protected App app; 34 | 35 | protected ActivityComponent getActivityComponent() { 36 | return DaggerActivityComponent.builder() 37 | .appComponent(App.getAppComponent()) 38 | .activityModule(getActivityModule()) 39 | .build(); 40 | } 41 | 42 | @Override 43 | protected void onCreate(@Nullable Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(getLayoutID());//设置主布局ID 46 | ButterKnife.bind(this);//添加注解在注入,一定要在setContentView之后使用 47 | init();//初始化全局的一些变量 48 | initInject();//注入依赖 49 | initAllMembersView();//初始化一些其他视图对象 50 | presenter.attachView(this); 51 | onCreateFinish();//onCreate完成时候调用 52 | } 53 | 54 | @Override 55 | protected void onDestroy() { 56 | super.onDestroy(); 57 | if (presenter != null) 58 | presenter.detachView(); 59 | } 60 | 61 | /** 62 | * 获取当前ActivityModule 63 | * 64 | * @return 65 | */ 66 | protected ActivityModule getActivityModule() { 67 | return new ActivityModule(this); 68 | } 69 | 70 | /** 71 | * 初始化全局变量 72 | */ 73 | protected void init() { 74 | activity = this; 75 | } 76 | 77 | /** 78 | * 返回主布局id 79 | */ 80 | protected abstract int getLayoutID(); 81 | 82 | /** 83 | * 初始化其他显示VIEW 84 | */ 85 | public void initAllMembersView() { 86 | } 87 | 88 | /** 89 | * 注入依赖 90 | */ 91 | protected abstract void initInject(); 92 | 93 | /** 94 | * onCreate完成时候调用,一般用于请求权限之类的操作 95 | */ 96 | protected void onCreateFinish(){ 97 | 98 | } 99 | 100 | @Override 101 | public void showErrorMsg(String msg) { 102 | 103 | } 104 | 105 | @Override 106 | public void stateError() { 107 | 108 | } 109 | 110 | @Override 111 | public void stateEmpty() { 112 | 113 | } 114 | 115 | @Override 116 | public void stateLoading() { 117 | 118 | } 119 | 120 | @Override 121 | public void stateMain() { 122 | 123 | } 124 | 125 | @Override 126 | public void toast(String msg) { 127 | ToastUtils.showLong(msg); 128 | } 129 | 130 | @Override 131 | public void showTip(int iconType, @NonNull String tipWord) { 132 | tipDialog = new QMUITipDialog.Builder(app) 133 | .setTipWord(tipWord) 134 | .setIconType(iconType) 135 | .create(); 136 | tipDialog.show(); 137 | } 138 | 139 | @Override 140 | public void showTip(@NonNull String tipWord) { 141 | tipDialog = new QMUITipDialog.Builder(app) 142 | .setTipWord(tipWord) 143 | .create(); 144 | tipDialog.show(); 145 | } 146 | 147 | @Override 148 | public void dismissTip() { 149 | if (tipDialog != null && tipDialog.isShowing()) 150 | tipDialog.dismiss(); 151 | } 152 | } 153 | --------------------------------------------------------------------------------