]> git.lizzy.rs Git - hydra-dragonfire.git/blob - convert/read_static.go
Add map component
[hydra-dragonfire.git] / convert / read_static.go
1 package convert
2
3 import (
4         "github.com/anon55555/mt"
5         "github.com/yuin/gopher-lua"
6 )
7
8 //go:generate ./read_mkauto.lua
9
10 func ReadBool(l *lua.LState, val lua.LValue, ptr *bool) {
11         if val.Type() != lua.LTBool {
12                 panic("invalid value for bool: must be a boolean")
13         }
14         *ptr = bool(val.(lua.LBool))
15 }
16
17 func ReadString(l *lua.LState, val lua.LValue, ptr *string) {
18         if val.Type() != lua.LTString {
19                 panic("invalid value for string: must be a string")
20         }
21         *ptr = string(val.(lua.LString))
22 }
23
24 func ReadSliceByte(l *lua.LState, val lua.LValue, ptr *[]byte) {
25         if val.Type() != lua.LTString {
26                 panic("invalid value for []byte: must be a string")
27         }
28         *ptr = []byte(val.(lua.LString))
29 }
30
31 func ReadSliceField(l *lua.LState, val lua.LValue, ptr *[]mt.Field) {
32         if val.Type() != lua.LTTable {
33                 panic("invalid value for []Field: must be a table")
34         }
35         val.(*lua.LTable).ForEach(func(k, v lua.LValue) {
36                 if k.Type() != lua.LTString || v.Type() != lua.LTString {
37                         panic("invalid value for Field: key and value must be strings")
38                 }
39                 *ptr = append(*ptr, mt.Field{Name: string(k.(lua.LString)), Value: string(v.(lua.LString))})
40         })
41 }
42
43 func ReadPointedThing(l *lua.LState, val lua.LValue, ptr *mt.PointedThing) {
44         if val.Type() != lua.LTTable {
45                 panic("invalid value for PointedThing: must be a table")
46         }
47         id := l.GetField(val, "id")
48
49         if id != lua.LNil {
50                 pt := &mt.PointedAO{}
51                 ReadAOID(l, id, &(*pt).ID)
52                 *ptr = pt
53         } else {
54                 pt := &mt.PointedNode{}
55                 ReadVec3Int16(l, l.GetField(val, "under"), &(*pt).Under)
56                 ReadVec3Int16(l, l.GetField(val, "above"), &(*pt).Above)
57                 *ptr = pt
58         }
59 }