Skip to content

Commit

Permalink
add luasocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Ildar Mulyukov committed Jun 12, 2020
1 parent 248ec4b commit e0e0217
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "app/src/main/jni/luasocket/luasocket"]
path = app/src/main/jni/luasocket/luasocket
url = https://github.com/diegonehab/luasocket
40 changes: 40 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,43 @@ android {

}

task copyFiles_luasocket1(type: Copy) {
from 'src/main/jni/luasocket/luasocket/src/ltn12.lua'
from 'src/main/jni/luasocket/luasocket/src/socket.lua'
from 'src/main/jni/luasocket/luasocket/src/mime.lua'
into 'src/main/assets'
}

task copyFiles_luasocket2(type: Copy) {
from 'src/main/jni/luasocket/luasocket/src/http.lua'
from 'src/main/jni/luasocket/luasocket/src/url.lua'
from 'src/main/jni/luasocket/luasocket/src/tp.lua'
from 'src/main/jni/luasocket/luasocket/src/ftp.lua'
from 'src/main/jni/luasocket/luasocket/src/headers.lua'
from 'src/main/jni/luasocket/luasocket/src/smtp.lua'
into 'src/main/assets/socket'
}

task fix_luasocket1 {
doLast {
exec {
workingDir 'src/main/assets'
commandLine 'sed', '-i', 's/socket.core/socket_core/', 'socket.lua'
}
}
}

task fix_luasocket2 {
doLast {
exec {
workingDir 'src/main/assets'
commandLine 'sed', '-i', 's/mime.core/mime_core/', 'mime.lua'
}
}
}

fix_luasocket1.dependsOn(copyFiles_luasocket1)
preBuild.dependsOn(fix_luasocket1)
fix_luasocket2.dependsOn(copyFiles_luasocket2)
preBuild.dependsOn(fix_luasocket2)

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/github/ildar/AndroidLuaSDK/Lua.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public int execute() throws LuaException {
L.setField(-2, "path"); // package
L.getField(-1, "cpath"); // package cpath
filesDir = main_instance.getFilesDir().toString() + "/../lib";
customPath = ";" + filesDir+"/?.so";
customPath = ";" + filesDir+"/lib?.so";
filesDir = main_instance.getExternalFilesDir(null).toString() + "/../lib";
customPath += ";" + filesDir+"/?.so";
customPath += ";" + filesDir+"/lib?.so";
L.pushString(customPath); // package cpath custom
L.concat(2); // package cpathCustom
L.setField(-2, "cpath"); // package
Expand Down
68 changes: 68 additions & 0 deletions app/src/main/jni/luasocket/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
LOCAL_PATH := $(call my-dir)

# Tweaks to reuse original luasocket makefile
O=o
SOCKET=usocket.o

# This is from ./luasocket/src/makefile

# DEBUG: NODEBUG DEBUG
# debug mode causes luasocket to collect and returns timing information useful
# for testing and debugging luasocket itself
DEBUG?=NODEBUG

#------
# Compiler and linker settings
# for Linux
DEF_linux=-DLUASOCKET_$(DEBUG)

#------
# Modules belonging to socket-core
#
SOCKET_OBJS= \
luasocket.$(O) \
timeout.$(O) \
buffer.$(O) \
io.$(O) \
auxiliar.$(O) \
compat.$(O) \
options.$(O) \
inet.$(O) \
$(SOCKET) \
except.$(O) \
select.$(O) \
tcp.$(O) \
udp.$(O)

#------
# Modules belonging mime-core
#
MIME_OBJS= \
mime.$(O) \
compat.$(O)
# skipping Unix sockets and Serial modules

# socket-core
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lua
LOCAL_C_INCLUDES += $(LOCAL_PATH)/luasocket/src
LOCAL_CFLAGS += $(DEF_linux)
LOCAL_MODULE := socket_core
LOCAL_SRC_FILES := $(SOCKET_OBJS:%o=luasocket/src/%c)
LOCAL_SHARED_LIBRARIES := luajava
# LOCAL_ALLOW_UNDEFINED_SYMBOLS = true
# LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

# mime-core
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lua
LOCAL_C_INCLUDES += $(LOCAL_PATH)/luasocket/src
LOCAL_CFLAGS += $(DEF_linux)
LOCAL_MODULE := mime_core
LOCAL_SRC_FILES := $(MIME_OBJS:%o=luasocket/src/%c)
LOCAL_SHARED_LIBRARIES := luajava
# LOCAL_ALLOW_UNDEFINED_SYMBOLS = true
# LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

1 change: 1 addition & 0 deletions app/src/main/jni/luasocket/luasocket
Submodule luasocket added at 5b18e4

0 comments on commit e0e0217

Please sign in to comment.