From dacf22af1e2e84f53ff5d9aa2d57007e9b686eb2 Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 8 May 2019 22:13:52 +0200 Subject: [PATCH] Simulating TCP socket; Alpha --- .../src/de/c3ma/ollo/mockup/ESP8266Net.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Net.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Net.java index 6bf43c5..d136dee 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Net.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Net.java @@ -1,20 +1,15 @@ package de.c3ma.ollo.mockup; -import java.io.File; import java.io.IOException; import java.io.InterruptedIOException; import java.net.ServerSocket; import java.net.Socket; -import java.nio.file.Files; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; -import org.luaj.vm2.lib.OneArgFunction; +import org.luaj.vm2.lib.ThreeArgFunction; import org.luaj.vm2.lib.TwoArgFunction; -import org.luaj.vm2.lib.ZeroArgFunction; - -import de.c3ma.ollo.LuaSimulation; /** * created at 29.12.2017 - 01:29:40
@@ -30,7 +25,7 @@ public class ESP8266Net extends TwoArgFunction { @Override public LuaValue call(LuaValue modname, LuaValue env) { env.checkglobals(); - final LuaTable net = new LuaTable(); + LuaValue net = LuaValue.tableOf(); net.set("createServer", new CreateServerFunction()); //FIXME net.set("send", new SendFunction()); @@ -40,21 +35,25 @@ public class ESP8266Net extends TwoArgFunction { return net; } - private class CreateServerFunction extends OneArgFunction { + private class CreateServerFunction extends TwoArgFunction { @Override - public LuaValue call(LuaValue arg) { - final LuaTable srv = new LuaTable(); - srv.set("listen", new ListenFunction()); - return srv; + public LuaValue call(LuaValue modname, LuaValue globalEnv) { + LuaValue cs = LuaValue.tableOf(); + cs.set("listen", new ListenFunction()); + return cs; } } - private class ListenFunction extends TwoArgFunction { + private class ListenFunction extends ThreeArgFunction { @Override - public LuaValue call(LuaValue port, LuaValue function) { + public LuaValue call(LuaValue self, LuaValue port, LuaValue function) { + if(!self.istable()) { + return NIL; + } + int portnumber = port.checkint(); LuaFunction onListenFunction = function.checkfunction();