aboutsummaryrefslogtreecommitdiff
path: root/comp_map.go
blob: c45155e3d58a114c9d7c8597df2baf10d69a7ae0 (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
package main

import (
	"github.com/anon55555/mt"
	"github.com/yuin/gopher-lua"
)

type CompMap struct {
	client   *Client
	mapdata *Map
	userdata *lua.LUserData
}

var compMapFuncs = map[string]lua.LGFunction{
	"get": l_comp_map_get,
	"set": l_comp_map_set,
}

func getCompMap(l *lua.LState) *CompMap {
	return l.CheckUserData(1).Value.(*CompMap)
}

func (comp *CompMap) create(client *Client, l *lua.LState) {
	comp.client = client
	comp.mapdata = newMap(l)
	comp.userdata = l.NewUserData()
	comp.userdata.Value = comp
	l.SetMetatable(comp.userdata, l.GetTypeMetatable("hydra.comp.map"))
}

func (comp *CompMap) push() lua.LValue {
	return comp.userdata
}

func (comp *CompMap) connect() {
}

func (comp *CompMap) process(pkt *mt.Pkt) {
	comp.mapdata.process(comp.client, pkt)
}

func l_comp_map_set(l *lua.LState) int {
	comp := getCompMap(l)
	comp.mapdata = getMap(l, 2)
	return 0
}

func l_comp_map_get(l *lua.LState) int {
	comp := getCompMap(l)
	l.Push(comp.mapdata.userdata)
	return 1
}