diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-01 18:09:48 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-01 18:09:48 +0200 |
commit | 9018d87c86806b2c6d7cabd964479031d2a1e7b1 (patch) | |
tree | abf57b2eb29a44cb0d7aa93c18bad68625c94da6 /comp_map.go | |
parent | ea4263290b2e7d82b29cc9809d98bf33528b1c61 (diff) | |
download | hydra-dragonfire-9018d87c86806b2c6d7cabd964479031d2a1e7b1.tar.xz |
Allow multiple clients to share a map
Diffstat (limited to 'comp_map.go')
-rw-r--r-- | comp_map.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/comp_map.go b/comp_map.go new file mode 100644 index 0000000..c45155e --- /dev/null +++ b/comp_map.go @@ -0,0 +1,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 +} |