diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java b/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java index 4b9fa275..b87ee15d 100644 --- a/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java +++ b/Android/LuaViewSDK/src/com/taobao/luaview/debug/DebugConnection.java @@ -14,13 +14,17 @@ public class DebugConnection extends Socket { private static final String EMULATOR_LOCALHOST = "10.0.2.2"; private static final String GENYMOTION_LOCALHOST = "10.0.3.2"; - private static final String DEVICE_LOCALHOST = "localhost"; + private static String DEVICE_LOCALHOST = "localhost"; private static final int PORT = 9876; private DataInputStream input = null; private DataOutputStream output = null; public boolean sendingEnabled = true; + + public static void setDeviceLocalhost(String deviceLocalhost) { + DEVICE_LOCALHOST = deviceLocalhost; + } private static String getDebugServerHost() { // Since genymotion runs in vbox it use different hostname to refer to adb host. diff --git a/Android/LuaViewSDK/src/com/taobao/luaview/vm/extend/BaseLib.java b/Android/LuaViewSDK/src/com/taobao/luaview/vm/extend/BaseLib.java index 1a7a14eb..acfc55f8 100644 --- a/Android/LuaViewSDK/src/com/taobao/luaview/vm/extend/BaseLib.java +++ b/Android/LuaViewSDK/src/com/taobao/luaview/vm/extend/BaseLib.java @@ -26,6 +26,7 @@ public BaseLib(org.luaj.vm2.lib.BaseLib baseLib, Globals globals) { public void extend(LuaValue env) { env.set("printLV", new printLV(baseLib)); + env.set("printLog", new printLog(baseLib)); } // "print", // (...) -> void @@ -56,4 +57,22 @@ public Varargs invoke(Varargs args) { return NONE; } } + + // "printLog(fileName, messsage)", send log info to LuaViewDebugger + final class printLog extends TwoArgFunction { + final org.luaj.vm2.lib.BaseLib baseLib; + + public log(org.luaj.vm2.lib.BaseLib baseLib) { + this.baseLib = baseLib; + } + + @Override public LuaValue call(LuaValue arg1, LuaValue arg2) { + String fileName = arg1.checkjstring(); + if (globals.debugConnection != null) { + globals.debugConnection.sendCmd("log", fileName, arg2.checkjstring()); + } + LogUtil.i(arg2); + return NONE; + } + } }