diff options
-rw-r--r-- | auth.go | 6 | ||||
-rw-r--r-- | builtin/client.lua | 1 | ||||
-rw-r--r-- | client.go | 13 | ||||
-rw-r--r-- | convert/push_auto.go (renamed from tolua/generated.go) | 180 | ||||
-rwxr-xr-x | convert/push_mkauto.lua (renamed from tolua/generate.lua) | 32 | ||||
-rw-r--r-- | convert/push_static.go (renamed from tolua/static.go) | 38 | ||||
-rw-r--r-- | convert/read_auto.go (renamed from fromlua/generated.go) | 6 | ||||
-rwxr-xr-x | convert/read_mkauto.lua (renamed from fromlua/generate.lua) | 10 | ||||
-rw-r--r-- | convert/read_static.go (renamed from fromlua/static.go) | 4 | ||||
-rw-r--r-- | convert/spec.lua (renamed from parse_spec.lua) | 0 | ||||
-rw-r--r-- | hydra.go | 4 |
11 files changed, 147 insertions, 147 deletions
@@ -3,7 +3,7 @@ package main import ( "github.com/HimbeerserverDE/srp" "github.com/anon55555/mt" - "github.com/dragonfireclient/hydra-dragonfire/tolua" + "github.com/dragonfireclient/hydra-dragonfire/convert" "github.com/yuin/gopher-lua" "strings" "time" @@ -57,7 +57,7 @@ func (auth *Auth) create(client *Client, l *lua.LState) { l.SetMetatable(auth.userdata, l.GetTypeMetatable("hydra.auth")) } -func (auth *Auth) tolua() lua.LValue { +func (auth *Auth) push() lua.LValue { return auth.userdata } @@ -90,7 +90,7 @@ func (auth *Auth) checkState(state authState, pkt *mt.Pkt) bool { return true } - auth.fail("received " + string(tolua.PktType(pkt)) + " in invalid state") + auth.fail("received " + string(convert.PushPktType(pkt)) + " in invalid state") return false } diff --git a/builtin/client.lua b/builtin/client.lua index b4ed556..a7618f4 100644 --- a/builtin/client.lua +++ b/builtin/client.lua @@ -1,4 +1,5 @@ --[[ builtin/client.lua ]]-- + function package.loaded.client() local address, name, password = unpack(arg) local client = hydra.client(address) @@ -3,8 +3,7 @@ package main import ( "errors" "github.com/anon55555/mt" - "github.com/dragonfireclient/hydra-dragonfire/fromlua" - "github.com/dragonfireclient/hydra-dragonfire/tolua" + "github.com/dragonfireclient/hydra-dragonfire/convert" "github.com/yuin/gopher-lua" "net" "sync" @@ -20,7 +19,7 @@ const ( type Component interface { create(client *Client, l *lua.LState) - tolua() lua.LValue + push() lua.LValue connect() process(pkt *mt.Pkt) } @@ -109,7 +108,7 @@ func l_client_index(l *lua.LState) int { if fun, exists := clientFuncs[key]; exists { l.Push(l.NewFunction(fun)) } else if component, exists := client.components[key]; exists { - l.Push(component.tolua()) + l.Push(component.push()) } else { l.Push(lua.LNil) } @@ -168,7 +167,7 @@ func l_client_connect(l *lua.LState) int { component.process(&pkt) } - if _, exists := client.subscribed[string(tolua.PktType(&pkt))]; exists || client.wildcard { + if _, exists := client.subscribed[string(convert.PushPktType(&pkt))]; exists || client.wildcard { client.queue <- &pkt } @@ -193,7 +192,7 @@ func l_client_poll(l *lua.LState) int { client := getClient(l) _, pkt, timeout := doPoll(l, []*Client{client}) - l.Push(tolua.Pkt(l, pkt)) + l.Push(convert.PushPkt(l, pkt)) l.Push(lua.LBool(timeout)) return 2 } @@ -258,7 +257,7 @@ func l_client_wildcard(l *lua.LState) int { func l_client_send(l *lua.LState) int { client := getClient(l) - cmd := fromlua.Cmd(l) + cmd := convert.ReadCmd(l) doAck := l.ToBool(4) client.mu.Lock() diff --git a/tolua/generated.go b/convert/push_auto.go index ec53231..282a5f5 100644 --- a/tolua/generated.go +++ b/convert/push_auto.go @@ -1,12 +1,12 @@ -// generated by generate.lua, DO NOT EDIT -package tolua +// generated by push_mkauto.lua, DO NOT EDIT +package convert import ( "github.com/anon55555/mt" "github.com/yuin/gopher-lua" ) -func AnimType(l *lua.LState, val mt.AnimType) lua.LValue { +func pushAnimType(l *lua.LState, val mt.AnimType) lua.LValue { switch val { case mt.NoAnim: return lua.LNil @@ -19,7 +19,7 @@ func AnimType(l *lua.LState, val mt.AnimType) lua.LValue { return lua.LNil } -func ChatMsgType(l *lua.LState, val mt.ChatMsgType) lua.LValue { +func pushChatMsgType(l *lua.LState, val mt.ChatMsgType) lua.LValue { switch val { case mt.RawMsg: return lua.LString("raw") @@ -34,7 +34,7 @@ func ChatMsgType(l *lua.LState, val mt.ChatMsgType) lua.LValue { return lua.LNil } -func HotbarParam(l *lua.LState, val mt.HotbarParam) lua.LValue { +func pushHotbarParam(l *lua.LState, val mt.HotbarParam) lua.LValue { switch val { case mt.HotbarSize: return lua.LString("size") @@ -47,7 +47,7 @@ func HotbarParam(l *lua.LState, val mt.HotbarParam) lua.LValue { return lua.LNil } -func HUDField(l *lua.LState, val mt.HUDField) lua.LValue { +func pushHUDField(l *lua.LState, val mt.HUDField) lua.LValue { switch val { case mt.HUDPos: return lua.LString("pos") @@ -80,7 +80,7 @@ func HUDField(l *lua.LState, val mt.HUDField) lua.LValue { return lua.LNil } -func HUDType(l *lua.LState, val mt.HUDType) lua.LValue { +func pushHUDType(l *lua.LState, val mt.HUDType) lua.LValue { switch val { case mt.ImgHUD: return lua.LString("img") @@ -99,7 +99,7 @@ func HUDType(l *lua.LState, val mt.HUDType) lua.LValue { return lua.LNil } -func KickReason(l *lua.LState, val mt.KickReason) lua.LValue { +func pushKickReason(l *lua.LState, val mt.KickReason) lua.LValue { switch val { case mt.WrongPasswd: return lua.LString("wrong_passwd") @@ -132,7 +132,7 @@ func KickReason(l *lua.LState, val mt.KickReason) lua.LValue { return lua.LNil } -func ModChanSig(l *lua.LState, val mt.ModChanSig) lua.LValue { +func pushModChanSig(l *lua.LState, val mt.ModChanSig) lua.LValue { switch val { case mt.JoinOK: return lua.LString("join_ok") @@ -151,7 +151,7 @@ func ModChanSig(l *lua.LState, val mt.ModChanSig) lua.LValue { return lua.LNil } -func PlayerListUpdateType(l *lua.LState, val mt.PlayerListUpdateType) lua.LValue { +func pushPlayerListUpdateType(l *lua.LState, val mt.PlayerListUpdateType) lua.LValue { switch val { case mt.InitPlayers: return lua.LString("init") @@ -164,7 +164,7 @@ func PlayerListUpdateType(l *lua.LState, val mt.PlayerListUpdateType) lua.LValue return lua.LNil } -func SoundSrcType(l *lua.LState, val mt.SoundSrcType) lua.LValue { +func pushSoundSrcType(l *lua.LState, val mt.SoundSrcType) lua.LValue { switch val { case mt.NoSrc: return lua.LNil @@ -177,7 +177,7 @@ func SoundSrcType(l *lua.LState, val mt.SoundSrcType) lua.LValue { return lua.LNil } -func AuthMethods(l *lua.LState, val mt.AuthMethods) lua.LValue { +func pushAuthMethods(l *lua.LState, val mt.AuthMethods) lua.LValue { tbl := l.NewTable() if val&mt.LegacyPasswd != 0 { l.SetField(tbl, "legacy_passwd", lua.LTrue) @@ -191,7 +191,7 @@ func AuthMethods(l *lua.LState, val mt.AuthMethods) lua.LValue { return tbl } -func CSMRestrictionFlags(l *lua.LState, val mt.CSMRestrictionFlags) lua.LValue { +func pushCSMRestrictionFlags(l *lua.LState, val mt.CSMRestrictionFlags) lua.LValue { tbl := l.NewTable() if val&mt.NoCSMs != 0 { l.SetField(tbl, "no_csms", lua.LTrue) @@ -211,7 +211,7 @@ func CSMRestrictionFlags(l *lua.LState, val mt.CSMRestrictionFlags) lua.LValue { return tbl } -func HUDFlags(l *lua.LState, val mt.HUDFlags) lua.LValue { +func pushHUDFlags(l *lua.LState, val mt.HUDFlags) lua.LValue { tbl := l.NewTable() if val&mt.ShowHotbar != 0 { l.SetField(tbl, "hotbar", lua.LTrue) @@ -237,26 +237,26 @@ func HUDFlags(l *lua.LState, val mt.HUDFlags) lua.LValue { return tbl } -func HUD(l *lua.LState, val mt.HUD) lua.LValue { +func pushHUD(l *lua.LState, val mt.HUD) lua.LValue { tbl := l.NewTable() - l.SetField(tbl, "align", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Align[0]), lua.LNumber(val.Align[1])})) + l.SetField(tbl, "align", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Align[0]), lua.LNumber(val.Align[1])})) l.SetField(tbl, "dir", lua.LNumber(val.Dir)) l.SetField(tbl, "item", lua.LNumber(val.Item)) l.SetField(tbl, "name", lua.LString(string(val.Name))) l.SetField(tbl, "number", lua.LNumber(val.Number)) - l.SetField(tbl, "offset", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Offset[0]), lua.LNumber(val.Offset[1])})) - l.SetField(tbl, "pos", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1])})) - l.SetField(tbl, "scale", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Scale[0]), lua.LNumber(val.Scale[1])})) - l.SetField(tbl, "size", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) + l.SetField(tbl, "offset", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Offset[0]), lua.LNumber(val.Offset[1])})) + l.SetField(tbl, "pos", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1])})) + l.SetField(tbl, "scale", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Scale[0]), lua.LNumber(val.Scale[1])})) + l.SetField(tbl, "size", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) l.SetField(tbl, "text", lua.LString(string(val.Text))) l.SetField(tbl, "text_2", lua.LString(string(val.Text2))) - l.SetField(tbl, "type", HUDType(l, val.Type)) - l.SetField(tbl, "world_pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.WorldPos[0]), lua.LNumber(val.WorldPos[1]), lua.LNumber(val.WorldPos[2])})) + l.SetField(tbl, "type", pushHUDType(l, val.Type)) + l.SetField(tbl, "world_pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.WorldPos[0]), lua.LNumber(val.WorldPos[1]), lua.LNumber(val.WorldPos[2])})) l.SetField(tbl, "z_index", lua.LNumber(val.ZIndex)) return tbl } -func Node(l *lua.LState, val mt.Node) lua.LValue { +func pushNode(l *lua.LState, val mt.Node) lua.LValue { tbl := l.NewTable() l.SetField(tbl, "param0", lua.LNumber(val.Param0)) l.SetField(tbl, "param1", lua.LNumber(val.Param1)) @@ -264,16 +264,16 @@ func Node(l *lua.LState, val mt.Node) lua.LValue { return tbl } -func TileAnim(l *lua.LState, val mt.TileAnim) lua.LValue { +func pushTileAnim(l *lua.LState, val mt.TileAnim) lua.LValue { tbl := l.NewTable() - l.SetField(tbl, "aspect_ratio", Vec2(l, [2]lua.LNumber{lua.LNumber(val.AspectRatio[0]), lua.LNumber(val.AspectRatio[1])})) + l.SetField(tbl, "aspect_ratio", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.AspectRatio[0]), lua.LNumber(val.AspectRatio[1])})) l.SetField(tbl, "duration", lua.LNumber(val.Duration)) - l.SetField(tbl, "n_frames", Vec2(l, [2]lua.LNumber{lua.LNumber(val.NFrames[0]), lua.LNumber(val.NFrames[1])})) - l.SetField(tbl, "type", AnimType(l, val.Type)) + l.SetField(tbl, "n_frames", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.NFrames[0]), lua.LNumber(val.NFrames[1])})) + l.SetField(tbl, "type", pushAnimType(l, val.Type)) return tbl } -func PktType(pkt *mt.Pkt) lua.LString { +func PushPktType(pkt *mt.Pkt) lua.LString { switch pkt.Cmd.(type) { case *mt.ToCltAcceptAuth: return lua.LString("accept_auth") @@ -396,58 +396,58 @@ func PktType(pkt *mt.Pkt) lua.LString { return "" } -func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { +func PushPkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { if pkt == nil { return lua.LNil } tbl := l.NewTable() - l.SetField(tbl, "_type", PktType(pkt)) + l.SetField(tbl, "_type", PushPktType(pkt)) switch val := pkt.Cmd.(type) { case *mt.ToCltAcceptAuth: l.SetField(tbl, "map_seed", lua.LNumber(val.MapSeed)) - l.SetField(tbl, "player_pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.PlayerPos[0]), lua.LNumber(val.PlayerPos[1]), lua.LNumber(val.PlayerPos[2])})) + l.SetField(tbl, "player_pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.PlayerPos[0]), lua.LNumber(val.PlayerPos[1]), lua.LNumber(val.PlayerPos[2])})) l.SetField(tbl, "send_interval", lua.LNumber(val.SendInterval)) - l.SetField(tbl, "sudo_auth_methods", AuthMethods(l, val.SudoAuthMethods)) + l.SetField(tbl, "sudo_auth_methods", pushAuthMethods(l, val.SudoAuthMethods)) case *mt.ToCltAddHUD: - l.SetField(tbl, "hud", HUD(l, val.HUD)) + l.SetField(tbl, "hud", pushHUD(l, val.HUD)) l.SetField(tbl, "id", lua.LNumber(val.ID)) case *mt.ToCltAddNode: l.SetField(tbl, "keep_meta", lua.LBool(val.KeepMeta)) - l.SetField(tbl, "node", Node(l, val.Node)) - l.SetField(tbl, "pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) + l.SetField(tbl, "node", pushNode(l, val.Node)) + l.SetField(tbl, "pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) case *mt.ToCltAddParticleSpawner: - l.SetField(tbl, "acc", Box3(l, [2][3]lua.LNumber{{lua.LNumber(val.Acc[0][0]), lua.LNumber(val.Acc[0][1]), lua.LNumber(val.Acc[0][2])}, {lua.LNumber(val.Acc[1][0]), lua.LNumber(val.Acc[1][1]), lua.LNumber(val.Acc[1][2])}})) + l.SetField(tbl, "acc", pushBox3(l, [2][3]lua.LNumber{{lua.LNumber(val.Acc[0][0]), lua.LNumber(val.Acc[0][1]), lua.LNumber(val.Acc[0][2])}, {lua.LNumber(val.Acc[1][0]), lua.LNumber(val.Acc[1][1]), lua.LNumber(val.Acc[1][2])}})) l.SetField(tbl, "amount", lua.LNumber(val.Amount)) - l.SetField(tbl, "anim_params", TileAnim(l, val.AnimParams)) + l.SetField(tbl, "anim_params", pushTileAnim(l, val.AnimParams)) l.SetField(tbl, "ao_collision", lua.LBool(val.AOCollision)) l.SetField(tbl, "collide", lua.LBool(val.Collide)) l.SetField(tbl, "collision_rm", lua.LBool(val.CollisionRm)) l.SetField(tbl, "duration", lua.LNumber(val.Duration)) - l.SetField(tbl, "expiration_time", Box1(l, [2]lua.LNumber{lua.LNumber(val.ExpirationTime[0]), lua.LNumber(val.ExpirationTime[1])})) + l.SetField(tbl, "expiration_time", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.ExpirationTime[0]), lua.LNumber(val.ExpirationTime[1])})) l.SetField(tbl, "glow", lua.LNumber(val.Glow)) l.SetField(tbl, "id", lua.LNumber(val.ID)) l.SetField(tbl, "node_param0", lua.LNumber(val.NodeParam0)) l.SetField(tbl, "node_param2", lua.LNumber(val.NodeParam2)) l.SetField(tbl, "node_tile", lua.LNumber(val.NodeTile)) - l.SetField(tbl, "pos", Box3(l, [2][3]lua.LNumber{{lua.LNumber(val.Pos[0][0]), lua.LNumber(val.Pos[0][1]), lua.LNumber(val.Pos[0][2])}, {lua.LNumber(val.Pos[1][0]), lua.LNumber(val.Pos[1][1]), lua.LNumber(val.Pos[1][2])}})) - l.SetField(tbl, "size", Box1(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) + l.SetField(tbl, "pos", pushBox3(l, [2][3]lua.LNumber{{lua.LNumber(val.Pos[0][0]), lua.LNumber(val.Pos[0][1]), lua.LNumber(val.Pos[0][2])}, {lua.LNumber(val.Pos[1][0]), lua.LNumber(val.Pos[1][1]), lua.LNumber(val.Pos[1][2])}})) + l.SetField(tbl, "size", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) l.SetField(tbl, "texture", lua.LString(string(val.Texture))) - l.SetField(tbl, "vel", Box3(l, [2][3]lua.LNumber{{lua.LNumber(val.Vel[0][0]), lua.LNumber(val.Vel[0][1]), lua.LNumber(val.Vel[0][2])}, {lua.LNumber(val.Vel[1][0]), lua.LNumber(val.Vel[1][1]), lua.LNumber(val.Vel[1][2])}})) + l.SetField(tbl, "vel", pushBox3(l, [2][3]lua.LNumber{{lua.LNumber(val.Vel[0][0]), lua.LNumber(val.Vel[0][1]), lua.LNumber(val.Vel[0][2])}, {lua.LNumber(val.Vel[1][0]), lua.LNumber(val.Vel[1][1]), lua.LNumber(val.Vel[1][2])}})) l.SetField(tbl, "vertical", lua.LBool(val.Vertical)) case *mt.ToCltAddPlayerVel: - l.SetField(tbl, "vel", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Vel[0]), lua.LNumber(val.Vel[1]), lua.LNumber(val.Vel[2])})) + l.SetField(tbl, "vel", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Vel[0]), lua.LNumber(val.Vel[1]), lua.LNumber(val.Vel[2])})) case *mt.ToCltBlkData: - l.SetField(tbl, "blkpos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Blkpos[0]), lua.LNumber(val.Blkpos[1]), lua.LNumber(val.Blkpos[2])})) + l.SetField(tbl, "blkpos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Blkpos[0]), lua.LNumber(val.Blkpos[1]), lua.LNumber(val.Blkpos[2])})) case *mt.ToCltBreath: l.SetField(tbl, "breath", lua.LNumber(val.Breath)) case *mt.ToCltChangeHUD: if val.Field == mt.HUDAlign { - l.SetField(tbl, "align", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Align[0]), lua.LNumber(val.Align[1])})) + l.SetField(tbl, "align", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Align[0]), lua.LNumber(val.Align[1])})) } if val.Field == mt.HUDDir { l.SetField(tbl, "dir", lua.LNumber(val.Dir)) } - l.SetField(tbl, "field", HUDField(l, val.Field)) + l.SetField(tbl, "field", pushHUDField(l, val.Field)) l.SetField(tbl, "id", lua.LNumber(val.ID)) if val.Field == mt.HUDItem { l.SetField(tbl, "item", lua.LNumber(val.Item)) @@ -459,13 +459,13 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "number", lua.LNumber(val.Number)) } if val.Field == mt.HUDOffset { - l.SetField(tbl, "offset", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Offset[0]), lua.LNumber(val.Offset[1])})) + l.SetField(tbl, "offset", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Offset[0]), lua.LNumber(val.Offset[1])})) } if val.Field == mt.HUDPos { - l.SetField(tbl, "pos", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1])})) + l.SetField(tbl, "pos", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1])})) } if val.Field == mt.HUDSize { - l.SetField(tbl, "size", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) + l.SetField(tbl, "size", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Size[0]), lua.LNumber(val.Size[1])})) } if val.Field == mt.HUDText { l.SetField(tbl, "text", lua.LString(string(val.Text))) @@ -474,7 +474,7 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "text_2", lua.LString(string(val.Text2))) } if val.Field == mt.HUDWorldPos { - l.SetField(tbl, "world_pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.WorldPos[0]), lua.LNumber(val.WorldPos[1]), lua.LNumber(val.WorldPos[2])})) + l.SetField(tbl, "world_pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.WorldPos[0]), lua.LNumber(val.WorldPos[1]), lua.LNumber(val.WorldPos[2])})) } if val.Field == mt.HUDZIndex { l.SetField(tbl, "z_index", lua.LNumber(val.ZIndex)) @@ -483,19 +483,19 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "sender", lua.LString(string(val.Sender))) l.SetField(tbl, "text", lua.LString(string(val.Text))) l.SetField(tbl, "timestamp", lua.LNumber(val.Timestamp)) - l.SetField(tbl, "type", ChatMsgType(l, val.Type)) + l.SetField(tbl, "type", pushChatMsgType(l, val.Type)) case *mt.ToCltCloudParams: - l.SetField(tbl, "ambient_color", Color(l, val.AmbientColor)) + l.SetField(tbl, "ambient_color", pushColor(l, val.AmbientColor)) l.SetField(tbl, "density", lua.LNumber(val.Density)) - l.SetField(tbl, "diffuse_color", Color(l, val.DiffuseColor)) + l.SetField(tbl, "diffuse_color", pushColor(l, val.DiffuseColor)) l.SetField(tbl, "height", lua.LNumber(val.Height)) - l.SetField(tbl, "speed", Vec2(l, [2]lua.LNumber{lua.LNumber(val.Speed[0]), lua.LNumber(val.Speed[1])})) + l.SetField(tbl, "speed", pushVec2(l, [2]lua.LNumber{lua.LNumber(val.Speed[0]), lua.LNumber(val.Speed[1])})) l.SetField(tbl, "thickness", lua.LNumber(val.Thickness)) case *mt.ToCltCSMRestrictionFlags: - l.SetField(tbl, "flags", CSMRestrictionFlags(l, val.Flags)) + l.SetField(tbl, "flags", pushCSMRestrictionFlags(l, val.Flags)) l.SetField(tbl, "map_range", lua.LNumber(val.MapRange)) case *mt.ToCltDeathScreen: - l.SetField(tbl, "point_at", Vec3(l, [3]lua.LNumber{lua.LNumber(val.PointAt[0]), lua.LNumber(val.PointAt[1]), lua.LNumber(val.PointAt[2])})) + l.SetField(tbl, "point_at", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.PointAt[0]), lua.LNumber(val.PointAt[1]), lua.LNumber(val.PointAt[2])})) l.SetField(tbl, "point_cam", lua.LBool(val.PointCam)) case *mt.ToCltDelParticleSpawner: l.SetField(tbl, "id", lua.LNumber(val.ID)) @@ -505,8 +505,8 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "len", lua.LNumber(val.Len)) l.SetField(tbl, "name", lua.LString(string(val.Name))) case *mt.ToCltEyeOffset: - l.SetField(tbl, "first", Vec3(l, [3]lua.LNumber{lua.LNumber(val.First[0]), lua.LNumber(val.First[1]), lua.LNumber(val.First[2])})) - l.SetField(tbl, "third", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Third[0]), lua.LNumber(val.Third[1]), lua.LNumber(val.Third[2])})) + l.SetField(tbl, "first", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.First[0]), lua.LNumber(val.First[1]), lua.LNumber(val.First[2])})) + l.SetField(tbl, "third", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Third[0]), lua.LNumber(val.Third[1]), lua.LNumber(val.Third[2])})) case *mt.ToCltFadeSound: l.SetField(tbl, "gain", lua.LNumber(val.Gain)) l.SetField(tbl, "id", lua.LNumber(val.ID)) @@ -518,7 +518,7 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "multiplier", lua.LBool(val.Multiplier)) l.SetField(tbl, "transition_time", lua.LNumber(val.TransitionTime)) case *mt.ToCltHello: - l.SetField(tbl, "auth_methods", AuthMethods(l, val.AuthMethods)) + l.SetField(tbl, "auth_methods", pushAuthMethods(l, val.AuthMethods)) l.SetField(tbl, "compression", lua.LNumber(val.Compression)) l.SetField(tbl, "proto_ver", lua.LNumber(val.ProtoVer)) l.SetField(tbl, "serialize_ver", lua.LNumber(val.SerializeVer)) @@ -526,8 +526,8 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { case *mt.ToCltHP: l.SetField(tbl, "hp", lua.LNumber(val.HP)) case *mt.ToCltHUDFlags: - l.SetField(tbl, "flags", HUDFlags(l, val.Flags)) - l.SetField(tbl, "mask", HUDFlags(l, val.Mask)) + l.SetField(tbl, "flags", pushHUDFlags(l, val.Flags)) + l.SetField(tbl, "mask", pushHUDFlags(l, val.Mask)) case *mt.ToCltInv: l.SetField(tbl, "inv", lua.LString(string(val.Inv))) case *mt.ToCltInvFormspec: @@ -536,18 +536,18 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { if val.Reason == mt.Custom || val.Reason == mt.Shutdown || val.Reason == mt.Crash { l.SetField(tbl, "custom", lua.LString(string(val.Custom))) } - l.SetField(tbl, "reason", KickReason(l, val.Reason)) + l.SetField(tbl, "reason", pushKickReason(l, val.Reason)) if val.Reason == mt.Shutdown || val.Reason == mt.Crash { l.SetField(tbl, "reconnect", lua.LBool(val.Reconnect)) } case *mt.ToCltLegacyKick: l.SetField(tbl, "reason", lua.LString(string(val.Reason))) case *mt.ToCltLocalPlayerAnim: - l.SetField(tbl, "dig", Box1(l, [2]lua.LNumber{lua.LNumber(val.Dig[0]), lua.LNumber(val.Dig[1])})) - l.SetField(tbl, "idle", Box1(l, [2]lua.LNumber{lua.LNumber(val.Idle[0]), lua.LNumber(val.Idle[1])})) + l.SetField(tbl, "dig", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.Dig[0]), lua.LNumber(val.Dig[1])})) + l.SetField(tbl, "idle", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.Idle[0]), lua.LNumber(val.Idle[1])})) l.SetField(tbl, "speed", lua.LNumber(val.Speed)) - l.SetField(tbl, "walk", Box1(l, [2]lua.LNumber{lua.LNumber(val.Walk[0]), lua.LNumber(val.Walk[1])})) - l.SetField(tbl, "walk_dig", Box1(l, [2]lua.LNumber{lua.LNumber(val.WalkDig[0]), lua.LNumber(val.WalkDig[1])})) + l.SetField(tbl, "walk", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.Walk[0]), lua.LNumber(val.Walk[1])})) + l.SetField(tbl, "walk_dig", pushBox1(l, [2]lua.LNumber{lua.LNumber(val.WalkDig[0]), lua.LNumber(val.WalkDig[1])})) case *mt.ToCltMediaPush: l.SetField(tbl, "data", lua.LString(string(val.Data))) l.SetField(tbl, "filename", lua.LString(string(val.Filename))) @@ -559,7 +559,7 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "sender", lua.LString(string(val.Sender))) case *mt.ToCltModChanSig: l.SetField(tbl, "channel", lua.LString(string(val.Channel))) - l.SetField(tbl, "signal", ModChanSig(l, val.Signal)) + l.SetField(tbl, "signal", pushModChanSig(l, val.Signal)) case *mt.ToCltMoonParams: l.SetField(tbl, "size", lua.LNumber(val.Size)) l.SetField(tbl, "texture", lua.LString(string(val.Texture))) @@ -567,7 +567,7 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "visible", lua.LBool(val.Visible)) case *mt.ToCltMovePlayer: l.SetField(tbl, "pitch", lua.LNumber(val.Pitch)) - l.SetField(tbl, "pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) + l.SetField(tbl, "pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) l.SetField(tbl, "yaw", lua.LNumber(val.Yaw)) case *mt.ToCltMovement: l.SetField(tbl, "air_accel", lua.LNumber(val.AirAccel)) @@ -593,56 +593,56 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "loop", lua.LBool(val.Loop)) l.SetField(tbl, "name", lua.LString(string(val.Name))) l.SetField(tbl, "pitch", lua.LNumber(val.Pitch)) - l.SetField(tbl, "pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) + l.SetField(tbl, "pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) l.SetField(tbl, "src_aoid", lua.LNumber(val.SrcAOID)) - l.SetField(tbl, "src_type", SoundSrcType(l, val.SrcType)) + l.SetField(tbl, "src_type", pushSoundSrcType(l, val.SrcType)) case *mt.ToCltPrivs: - l.SetField(tbl, "privs", StringSet(l, val.Privs)) + l.SetField(tbl, "privs", pushStringSet(l, val.Privs)) case *mt.ToCltRemoveNode: - l.SetField(tbl, "pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) + l.SetField(tbl, "pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) case *mt.ToCltRmHUD: l.SetField(tbl, "id", lua.LNumber(val.ID)) case *mt.ToCltSetHotbarParam: l.SetField(tbl, "img", lua.LString(string(val.Img))) - l.SetField(tbl, "param", HotbarParam(l, val.Param)) + l.SetField(tbl, "param", pushHotbarParam(l, val.Param)) l.SetField(tbl, "size", lua.LNumber(val.Size)) case *mt.ToCltShowFormspec: l.SetField(tbl, "formname", lua.LString(string(val.Formname))) l.SetField(tbl, "formspec", lua.LString(string(val.Formspec))) case *mt.ToCltSkyParams: - l.SetField(tbl, "bg_color", Color(l, val.BgColor)) + l.SetField(tbl, "bg_color", pushColor(l, val.BgColor)) l.SetField(tbl, "clouds", lua.LBool(val.Clouds)) if val.Type == "regular" { - l.SetField(tbl, "dawn_horizon", Color(l, val.DawnHorizon)) + l.SetField(tbl, "dawn_horizon", pushColor(l, val.DawnHorizon)) } if val.Type == "regular" { - l.SetField(tbl, "dawn_sky", Color(l, val.DawnSky)) + l.SetField(tbl, "dawn_sky", pushColor(l, val.DawnSky)) } if val.Type == "regular" { - l.SetField(tbl, "day_horizon", Color(l, val.DayHorizon)) + l.SetField(tbl, "day_horizon", pushColor(l, val.DayHorizon)) } if val.Type == "regular" { - l.SetField(tbl, "day_sky", Color(l, val.DaySky)) + l.SetField(tbl, "day_sky", pushColor(l, val.DaySky)) } l.SetField(tbl, "fog_tint_type", lua.LString(string(val.FogTintType))) if val.Type == "regular" { - l.SetField(tbl, "indoor", Color(l, val.Indoor)) + l.SetField(tbl, "indoor", pushColor(l, val.Indoor)) } - l.SetField(tbl, "moon_fog_tint", Color(l, val.MoonFogTint)) + l.SetField(tbl, "moon_fog_tint", pushColor(l, val.MoonFogTint)) if val.Type == "regular" { - l.SetField(tbl, "night_horizon", Color(l, val.NightHorizon)) + l.SetField(tbl, "night_horizon", pushColor(l, val.NightHorizon)) } if val.Type == "regular" { - l.SetField(tbl, "night_sky", Color(l, val.NightSky)) + l.SetField(tbl, "night_sky", pushColor(l, val.NightSky)) } - l.SetField(tbl, "sun_fog_tint", Color(l, val.SunFogTint)) + l.SetField(tbl, "sun_fog_tint", pushColor(l, val.SunFogTint)) if val.Type == "skybox" { - l.SetField(tbl, "textures", TextureList(l, val.Textures)) + l.SetField(tbl, "textures", pushTextureList(l, val.Textures)) } l.SetField(tbl, "type", lua.LString(string(val.Type))) case *mt.ToCltSpawnParticle: - l.SetField(tbl, "acc", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Acc[0]), lua.LNumber(val.Acc[1]), lua.LNumber(val.Acc[2])})) - l.SetField(tbl, "anim_params", TileAnim(l, val.AnimParams)) + l.SetField(tbl, "acc", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Acc[0]), lua.LNumber(val.Acc[1]), lua.LNumber(val.Acc[2])})) + l.SetField(tbl, "anim_params", pushTileAnim(l, val.AnimParams)) l.SetField(tbl, "ao_collision", lua.LBool(val.AOCollision)) l.SetField(tbl, "collide", lua.LBool(val.Collide)) l.SetField(tbl, "collision_rm", lua.LBool(val.CollisionRm)) @@ -651,16 +651,16 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "node_param0", lua.LNumber(val.NodeParam0)) l.SetField(tbl, "node_param2", lua.LNumber(val.NodeParam2)) l.SetField(tbl, "node_tile", lua.LNumber(val.NodeTile)) - l.SetField(tbl, "pos", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) + l.SetField(tbl, "pos", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Pos[0]), lua.LNumber(val.Pos[1]), lua.LNumber(val.Pos[2])})) l.SetField(tbl, "size", lua.LNumber(val.Size)) l.SetField(tbl, "texture", lua.LString(string(val.Texture))) - l.SetField(tbl, "vel", Vec3(l, [3]lua.LNumber{lua.LNumber(val.Vel[0]), lua.LNumber(val.Vel[1]), lua.LNumber(val.Vel[2])})) + l.SetField(tbl, "vel", pushVec3(l, [3]lua.LNumber{lua.LNumber(val.Vel[0]), lua.LNumber(val.Vel[1]), lua.LNumber(val.Vel[2])})) l.SetField(tbl, "vertical", lua.LBool(val.Vertical)) case *mt.ToCltSRPBytesSaltB: l.SetField(tbl, "b", lua.LString(string(val.B))) l.SetField(tbl, "salt", lua.LString(string(val.Salt))) case *mt.ToCltStarParams: - l.SetField(tbl, "color", Color(l, val.Color)) + l.SetField(tbl, "color", pushColor(l, val.Color)) l.SetField(tbl, "count", lua.LNumber(val.Count)) l.SetField(tbl, "size", lua.LNumber(val.Size)) l.SetField(tbl, "visible", lua.LBool(val.Visible)) @@ -677,8 +677,8 @@ func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { l.SetField(tbl, "speed", lua.LNumber(val.Speed)) l.SetField(tbl, "time", lua.LNumber(val.Time)) case *mt.ToCltUpdatePlayerList: - l.SetField(tbl, "players", StringList(l, val.Players)) - l.SetField(tbl, "type", PlayerListUpdateType(l, val.Type)) + l.SetField(tbl, "players", pushStringList(l, val.Players)) + l.SetField(tbl, "type", pushPlayerListUpdateType(l, val.Type)) } return tbl } diff --git a/tolua/generate.lua b/convert/push_mkauto.lua index 3117713..3e02932 100755 --- a/tolua/generate.lua +++ b/convert/push_mkauto.lua @@ -1,11 +1,11 @@ #!/usr/bin/env lua -dofile("../parse_spec.lua") +require("spec") local funcs = "" for name, fields in spairs(parse_spec("client/enum")) do local camel = camel_case(name) - funcs = funcs .. "func " .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\tswitch val {\n" + funcs = funcs .. "func push" .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\tswitch val {\n" for _, var in ipairs(fields) do funcs = funcs .. "\tcase mt." .. apply_prefix(fields, var) .. ":\n\t\t" .. @@ -17,7 +17,7 @@ end for name, fields in spairs(parse_spec("client/flag")) do local camel = camel_case(name) - funcs = funcs .. "func " .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\ttbl := l.NewTable()\n" + funcs = funcs .. "func push" .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\ttbl := l.NewTable()\n" for _, var in ipairs(fields) do funcs = funcs .. "\tif val&mt." .. apply_prefix(fields, var) @@ -32,11 +32,11 @@ local tolua = { fixed_string = "lua.LString(string(VAL[:]))", boolean = "lua.LBool(VAL)", number = "lua.LNumber(VAL)", - vec2 = "Vec2(l, [2]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1])})", - vec3 = "Vec3(l, [3]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1]), lua.LNumber(VAL[2])})", - box1 = "Box1(l, [2]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1])})", - box2 = "Box2(l, [2][2]lua.LNumber{{lua.LNumber(VAL[0][0]), lua.LNumber(VAL[0][1])}, {lua.LNumber(VAL[1][0]), lua.LNumber(VAL[1][1])}})", - box3 = "Box3(l, [2][3]lua.LNumber{{lua.LNumber(VAL[0][0]), lua.LNumber(VAL[0][1]), lua.LNumber(VAL[0][2])}, {lua.LNumber(VAL[1][0]), lua.LNumber(VAL[1][1]), lua.LNumber(VAL[1][2])}})", + vec2 = "pushVec2(l, [2]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1])})", + vec3 = "pushVec3(l, [3]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1]), lua.LNumber(VAL[2])})", + box1 = "pushBox1(l, [2]lua.LNumber{lua.LNumber(VAL[0]), lua.LNumber(VAL[1])})", + box2 = "pushBox2(l, [2][2]lua.LNumber{{lua.LNumber(VAL[0][0]), lua.LNumber(VAL[0][1])}, {lua.LNumber(VAL[1][0]), lua.LNumber(VAL[1][1])}})", + box3 = "pushBox3(l, [2][3]lua.LNumber{{lua.LNumber(VAL[0][0]), lua.LNumber(VAL[0][1]), lua.LNumber(VAL[0][2])}, {lua.LNumber(VAL[1][0]), lua.LNumber(VAL[1][1]), lua.LNumber(VAL[1][2])}})", } local function fields_tolua(fields, indent) @@ -58,7 +58,7 @@ local function fields_tolua(fields, indent) if tolua[type] then impl = impl .. tolua[type]:gsub("VAL", camel) else - impl = impl .. camel_case(type) .. "(l, " .. camel .. ")" + impl = impl .. "push" .. camel_case(type) .. "(l, " .. camel .. ")" end impl = impl .. ")\n" @@ -74,7 +74,7 @@ end for name, fields in spairs(parse_spec("client/struct", true)) do local camel = camel_case(name) funcs = funcs - .. "func " .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\ttbl := l.NewTable()\n" + .. "func push" .. camel .. "(l *lua.LState, val mt." .. camel .. ") lua.LValue {\n\ttbl := l.NewTable()\n" .. fields_tolua(fields, "\t") .. "\treturn tbl\n}\n\n" end @@ -93,10 +93,10 @@ for name, fields in spairs(parse_spec("client/pkt", true)) do end end -local f = io.open("generated.go", "w") +local f = io.open("push_auto.go", "w") f:write([[ -// generated by generate.lua, DO NOT EDIT -package tolua +// generated by push_mkauto.lua, DO NOT EDIT +package convert import ( "github.com/anon55555/mt" @@ -104,7 +104,7 @@ import ( ) ]] .. funcs .. [[ -func PktType(pkt *mt.Pkt) lua.LString { +func PushPktType(pkt *mt.Pkt) lua.LString { switch pkt.Cmd.(type) { ]] .. pkt_type_impl .. [[ } @@ -112,12 +112,12 @@ func PktType(pkt *mt.Pkt) lua.LString { return "" } -func Pkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { +func PushPkt(l *lua.LState, pkt *mt.Pkt) lua.LValue { if pkt == nil { return lua.LNil } tbl := l.NewTable() - l.SetField(tbl, "_type", PktType(pkt)) + l.SetField(tbl, "_type", PushPktType(pkt)) switch val := pkt.Cmd.(type) { ]] .. pkt_impl .. [[ } diff --git a/tolua/static.go b/convert/push_static.go index 30d56ef..4eb7cb0 100644 --- a/tolua/static.go +++ b/convert/push_static.go @@ -1,4 +1,4 @@ -package tolua +package convert import ( "github.com/anon55555/mt" @@ -6,16 +6,16 @@ import ( "image/color" ) -//go:generate ./generate.lua +//go:generate ./push_mkauto.lua -func pushVec2(l *lua.LState, val [2]lua.LNumber) { +func vec2(l *lua.LState, val [2]lua.LNumber) { l.Push(l.GetGlobal("vec2")) l.Push(val[0]) l.Push(val[1]) l.Call(2, 1) } -func pushVec3(l *lua.LState, val [3]lua.LNumber) { +func vec3(l *lua.LState, val [3]lua.LNumber) { l.Push(l.GetGlobal("vec3")) l.Push(val[0]) l.Push(val[1]) @@ -29,17 +29,17 @@ func popValue(l *lua.LState) lua.LValue { return ret } -func Vec2(l *lua.LState, val [2]lua.LNumber) lua.LValue { - pushVec2(l, val) +func pushVec2(l *lua.LState, val [2]lua.LNumber) lua.LValue { + vec2(l, val) return popValue(l) } -func Vec3(l *lua.LState, val [3]lua.LNumber) lua.LValue { - pushVec3(l, val) +func pushVec3(l *lua.LState, val [3]lua.LNumber) lua.LValue { + vec3(l, val) return popValue(l) } -func Box1(l *lua.LState, val [2]lua.LNumber) lua.LValue { +func pushBox1(l *lua.LState, val [2]lua.LNumber) lua.LValue { l.Push(l.GetGlobal("box")) l.Push(val[0]) l.Push(val[1]) @@ -47,23 +47,23 @@ func Box1(l *lua.LState, val [2]lua.LNumber) lua.LValue { return popValue(l) } -func Box2(l *lua.LState, val [2][2]lua.LNumber) lua.LValue { +func pushBox2(l *lua.LState, val [2][2]lua.LNumber) lua.LValue { l.Push(l.GetGlobal("box")) - pushVec2(l, val[0]) - pushVec2(l, val[1]) + vec2(l, val[0]) + vec2(l, val[1]) l.Call(2, 1) return popValue(l) } -func Box3(l *lua.LState, val [2][3]lua.LNumber) lua.LValue { +func pushBox3(l *lua.LState, val [2][3]lua.LNumber) lua.LValue { l.Push(l.GetGlobal("box")) - pushVec3(l, val[0]) - pushVec3(l, val[1]) + vec3(l, val[0]) + vec3(l, val[1]) l.Call(2, 1) return popValue(l) } -func Color(l *lua.LState, val color.NRGBA) lua.LValue { +func pushColor(l *lua.LState, val color.NRGBA) lua.LValue { tbl := l.NewTable() l.SetField(tbl, "r", lua.LNumber(val.R)) l.SetField(tbl, "g", lua.LNumber(val.G)) @@ -72,7 +72,7 @@ func Color(l *lua.LState, val color.NRGBA) lua.LValue { return tbl } -func StringSet(l *lua.LState, val []string) lua.LValue { +func pushStringSet(l *lua.LState, val []string) lua.LValue { tbl := l.NewTable() for _, str := range val { l.SetField(tbl, str, lua.LTrue) @@ -88,10 +88,10 @@ func stringList[T ~string](l *lua.LState, val []T) lua.LValue { return tbl } -func StringList(l *lua.LState, val []string) lua.LValue { +func pushStringList(l *lua.LState, val []string) lua.LValue { return stringList[string](l, val) } -func TextureList(l *lua.LState, val []mt.Texture) lua.LValue { +func pushTextureList(l *lua.LState, val []mt.Texture) lua.LValue { return stringList[mt.Texture](l, val) } diff --git a/fromlua/generated.go b/convert/read_auto.go index c93c229..c5a39be 100644 --- a/fromlua/generated.go +++ b/convert/read_auto.go @@ -1,5 +1,5 @@ -// generated by generate.lua, DO NOT EDIT -package fromlua +// generated by read_mkauto.lua, DO NOT EDIT +package convert import ( "github.com/anon55555/mt" @@ -181,7 +181,7 @@ func readVec3Int32(l *lua.LState, val lua.LValue, ptr *[3]int32) { readInt32(l, l.GetField(val, "z"), &(*ptr)[2]) } -func Cmd(l *lua.LState) mt.Cmd { +func ReadCmd(l *lua.LState) mt.Cmd { str := l.CheckString(2) switch str { case "chat_msg": diff --git a/fromlua/generate.lua b/convert/read_mkauto.lua index 75899b7..f749f99 100755 --- a/fromlua/generate.lua +++ b/convert/read_mkauto.lua @@ -1,5 +1,5 @@ #!/usr/bin/env lua -dofile("../parse_spec.lua") +require("spec") local readers = { SliceByte = true, @@ -175,10 +175,10 @@ for _, fn in spairs(readers) do end end -local f = io.open("generated.go", "w") +local f = io.open("read_auto.go", "w") f:write([[ -// generated by generate.lua, DO NOT EDIT -package fromlua +// generated by read_mkauto.lua, DO NOT EDIT +package convert import ( "github.com/anon55555/mt" @@ -186,7 +186,7 @@ import ( ) ]] .. funcs .. [[ -func Cmd(l *lua.LState) mt.Cmd { +func ReadCmd(l *lua.LState) mt.Cmd { str := l.CheckString(2) switch str { ]] .. pkt_impl .. [[ diff --git a/fromlua/static.go b/convert/read_static.go index b989db8..2f62473 100644 --- a/fromlua/static.go +++ b/convert/read_static.go @@ -1,11 +1,11 @@ -package fromlua +package convert import ( "github.com/anon55555/mt" "github.com/yuin/gopher-lua" ) -//go:generate ./generate.lua +//go:generate ./read_mkauto.lua func readBool(l *lua.LState, val lua.LValue, ptr *bool) { if val.Type() != lua.LTBool { diff --git a/parse_spec.lua b/convert/spec.lua index 588f4d7..588f4d7 100644 --- a/parse_spec.lua +++ b/convert/spec.lua @@ -2,7 +2,7 @@ package main import ( _ "embed" - "github.com/dragonfireclient/hydra-dragonfire/tolua" + "github.com/dragonfireclient/hydra-dragonfire/convert" "github.com/yuin/gopher-lua" "os" "os/signal" @@ -63,7 +63,7 @@ func l_poll(l *lua.LState) int { } else { l.Push(client.userdata) } - l.Push(tolua.Pkt(l, pkt)) + l.Push(convert.PushPkt(l, pkt)) l.Push(lua.LBool(timeout)) return 3 } |