aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed/net.lua.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/embed/net.lua.h')
-rw-r--r--src/lua/embed/net.lua.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lua/embed/net.lua.h b/src/lua/embed/net.lua.h
new file mode 100644
index 0000000..73b60c3
--- /dev/null
+++ b/src/lua/embed/net.lua.h
@@ -0,0 +1,61 @@
+/* net.lua */
+static const char* net_lua = R"(
+jin.net = jin.net or {}
+
+--[[
+socketͨŵ
+* INT
+* FLOAT
+* BOOL
+* STRING
+STRINGжҽ磬0β
+һЭ鶨ӣðЭͳһһluaļ
+-- s2c_package.lua
+local INT = jin.net.dataType.INT
+local FLOAT = jin.net.dataType.FLOAT
+local BOOL = jin.net.dataType.BOOL
+local STRING = jin.net.dataType.STRING
+Skill = {
+ id = INT,
+ damage = FLOAT,
+ range = FLOAT,
+ description = STRING
+}
+local data, size = jin.net.serialize(Message.Skill, message)
+Socket:send(data, size)
+յʱ
+local data, size = Socket:receive()
+local message = jin.net.deserialize(Message.Skill, data, size)
+]]
+
+jin.net.INT = 1
+jin.net.FLOAT = 2
+jin.net.BOOL = 3
+jin.net.STRING = 4
+
+jin.net.deserialize = function(prototype, data, size)
+ local message = {}
+ local i = 1
+ for k, t in pairs(prototype) do
+ message[k] = data[i]
+ i = i + 1
+ end
+ return message
+end
+
+jin.net.serialize = function(prototype, message)
+ local data = ""
+ local size = 0
+ for i, v in pairs(message) do
+ data, size = jin.bit.write(data, size, v)
+ end
+ return data, size
+end
+
+-- Э
+jin.net.decode = function()
+
+end
+
+)"; \ No newline at end of file