aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed/net.lua.h
blob: 73b60c366c36d84f4544b3c4df04f42aa3cccac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 

)";