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 |
--------------------------------------------------------------------------------