GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - haodynasty/AndroidLuaExample: Lua 5.3.3 and LuaJava ported to Android example

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
app
app
 
 
gradle/wrapper
gradle/wrapper
 
 
luajava
luajava
 
 
old
old
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

AndroidLuaExample

update to Lua 5.3.3 and LuaJava ported to Android example

License Download

Import

add to build.gradle,${latest.version} is Download

dependencies {
    compile 'com.blakequ.luajava:luajava:${latest.version}'
}

maven

<dependency>
  <groupId>com.blakequ.luajava</groupId>
  <artifactId>luajava</artifactId>
  <version>${latest.version}</version>
  <type>pom</type>
</dependency>

How to use

you can download example and study how to use. add proguard rules

# luajava
-keep class org.keplerproject.luajava.**{*;}
# For native methods
-keepclasseswithmembernames class * {
    native <methods>;
}

1. init lua

init lua file only once after start app

private void initLua(){
        mLuaState = LuaStateFactory.newLuaState();
        mLuaState.openLibs();
        //push Log object to lua, in lua using like: Log:i(TAG, "this log can show in AS logcat window")
        try {
            mLuaState.pushObjectValue(Log.class);
            mLuaState.setGlobal("Log");
        } catch (LuaException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

2. add lua file to raw

app/src/main/res/raw/luafile.lua

function GetVersion(info, intvalue)
    Log:i("LuaLog", info..intvalue)
    print('this log')
    return 1
end

3. invoke lua function

private void executeLuaFile()
    {
            mLuaState.getGlobal("GetVersion");
            mLuaState.pushString("reload lua test");// input params
            mLuaState.pushNumber(10);
            mLuaState.call(2, 1);//2 input, 1 output
            String result = mLuaState.toString(-1);
            if (result == null){
                System.out.println("GetVersion return empty value");
            }else {
                System.out.println("GetVersion return value"+result);
            }
    }

4. invoke lua and error handle

private void executeLuaFile2()
    {
            //in lua file not exist this method:GetNotMethod
            mLuaState.getGlobal("GetNotMethod");
            mLuaState.pushString("reload lua test");// input params
            mLuaState.pushNumber(10);//not use pushInteger
            //if using call will throw exception(can not catch), so you must use pcall
            //success to invoke method if return 0, otherwise is error.
            int retCode = mLuaState.pcall(2, 1, -1);//2 input, 1 output
            String result = mLuaState.toString(-1);
            if (retCode != 0){
                LogUtils.e(TAG, "Fail to invoke GetNotMethod by lua errorCode:"+retCode+" errorMsg:"+result);
            }else {
                if (result == null){
                    System.out.println("GetVersion return empty value");
                }else {
                    System.out.println("GetVersion return value"+result);
                }
            }
    }

Link

  • AndroLua-mkottman
  • AndroLua-new
  • LuaScriptCore

About

Lua 5.3.3 and LuaJava ported to Android example

Topics

android-luaandrolualualuajava

Resources

Readme
MIT license
Activity

Stars

117 stars

Watchers

6 watching

Forks

22 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.