]> git.lizzy.rs Git - hydra-dragonfire.git/commitdiff
Add convert.go to tree
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 28 May 2022 14:09:50 +0000 (16:09 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 28 May 2022 14:09:50 +0000 (16:09 +0200)
.gitignore
convert.go [new file with mode: 0644]
mkconvert.lua

index 7e48585eeca12be723e8e3ee7087bf9b69eaed24..83f02065ddfc215f8f31d8b9c7fbdf33aa6031b4 100644 (file)
@@ -1,2 +1 @@
 hydra
-convert.go
diff --git a/convert.go b/convert.go
new file mode 100644 (file)
index 0000000..b53b6b9
--- /dev/null
@@ -0,0 +1,882 @@
+// generated by mkconvert.lua, DO NOT EDIT
+package main
+
+import (
+       "github.com/Shopify/go-lua"
+       "github.com/anon55555/mt"
+)
+
+func luaPushAnimType(l *lua.State, val mt.AnimType) {
+       switch val {
+       case mt.NoAnim:
+               l.PushNil()
+       case mt.VerticalFrameAnim:
+               l.PushString("vertical_frame")
+       case mt.SpriteSheetAnim:
+               l.PushString("sprite_sheet")
+       }
+}
+
+func luaPushChatMsgType(l *lua.State, val mt.ChatMsgType) {
+       switch val {
+       case mt.RawMsg:
+               l.PushString("raw")
+       case mt.NormalMsg:
+               l.PushString("normal")
+       case mt.AnnounceMsg:
+               l.PushString("announce")
+       case mt.SysMsg:
+               l.PushString("sys")
+       }
+}
+
+func luaPushHotbarParam(l *lua.State, val mt.HotbarParam) {
+       switch val {
+       case mt.HotbarSize:
+               l.PushString("size")
+       case mt.HotbarImg:
+               l.PushString("img")
+       case mt.HotbarSelImg:
+               l.PushString("sel_img")
+       }
+}
+
+func luaPushHUDField(l *lua.State, val mt.HUDField) {
+       switch val {
+       case mt.HUDPos:
+               l.PushString("pos")
+       case mt.HUDName:
+               l.PushString("name")
+       case mt.HUDScale:
+               l.PushString("scale")
+       case mt.HUDText:
+               l.PushString("text")
+       case mt.HUDNumber:
+               l.PushString("number")
+       case mt.HUDItem:
+               l.PushString("item")
+       case mt.HUDDir:
+               l.PushString("dir")
+       case mt.HUDAlign:
+               l.PushString("align")
+       case mt.HUDOffset:
+               l.PushString("offset")
+       case mt.HUDWorldPos:
+               l.PushString("world_pos")
+       case mt.HUDSize:
+               l.PushString("size")
+       case mt.HUDZIndex:
+               l.PushString("z_index")
+       case mt.HUDText2:
+               l.PushString("text_2")
+       }
+}
+
+func luaPushHUDType(l *lua.State, val mt.HUDType) {
+       switch val {
+       case mt.ImgHUD:
+               l.PushString("img")
+       case mt.TextHUD:
+               l.PushString("text")
+       case mt.StatbarHUD:
+               l.PushString("statbar")
+       case mt.InvHUD:
+               l.PushString("inv")
+       case mt.WaypointHUD:
+               l.PushString("waypoint")
+       case mt.ImgWaypointHUD:
+               l.PushString("img_waypoint")
+       }
+}
+
+func luaPushKickReason(l *lua.State, val mt.KickReason) {
+       switch val {
+       case mt.WrongPasswd:
+               l.PushString("wrong_passwd")
+       case mt.UnexpectedData:
+               l.PushString("unexpected_data")
+       case mt.SrvIsSingleplayer:
+               l.PushString("srv_is_singleplayer")
+       case mt.UnsupportedVer:
+               l.PushString("unsupported_ver")
+       case mt.BadNameChars:
+               l.PushString("bad_name_chars")
+       case mt.BadName:
+               l.PushString("bad_name")
+       case mt.TooManyClts:
+               l.PushString("too_many_clts")
+       case mt.EmptyPasswd:
+               l.PushString("empty_passwd")
+       case mt.AlreadyConnected:
+               l.PushString("already_connected")
+       case mt.SrvErr:
+               l.PushString("srv_err")
+       case mt.Custom:
+               l.PushString("custom")
+       case mt.Shutdown:
+               l.PushString("shutdown")
+       case mt.Crash:
+               l.PushString("crash")
+       }
+}
+
+func luaPushModChanSig(l *lua.State, val mt.ModChanSig) {
+       switch val {
+       case mt.JoinOK:
+               l.PushString("join_ok")
+       case mt.JoinFail:
+               l.PushString("join_fail")
+       case mt.LeaveOK:
+               l.PushString("leave_ok")
+       case mt.LeaveFail:
+               l.PushString("leave_fail")
+       case mt.NotRegistered:
+               l.PushString("not_registered")
+       case mt.SetState:
+               l.PushString("set_state")
+       }
+}
+
+func luaPushPlayerListUpdateType(l *lua.State, val mt.PlayerListUpdateType) {
+       switch val {
+       case mt.InitPlayers:
+               l.PushString("init")
+       case mt.AddPlayers:
+               l.PushString("add")
+       case mt.RemovePlayers:
+               l.PushString("remove")
+       }
+}
+
+func luaPushSoundSrcType(l *lua.State, val mt.SoundSrcType) {
+       switch val {
+       case mt.NoSrc:
+               l.PushNil()
+       case mt.PosSrc:
+               l.PushString("pos")
+       case mt.AOSrc:
+               l.PushString("ao")
+       }
+}
+
+func luaPushAuthMethods(l *lua.State, val mt.AuthMethods) {
+       l.NewTable()
+       if val&mt.LegacyPasswd != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "legacy_passwd")
+       }
+       if val&mt.SRP != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "srp")
+       }
+       if val&mt.FirstSRP != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "first_srp")
+       }
+}
+
+func luaPushCSMRestrictionFlags(l *lua.State, val mt.CSMRestrictionFlags) {
+       l.NewTable()
+       if val&mt.NoCSMs != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "no_csms")
+       }
+       if val&mt.NoChatMsgs != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "no_chat_msgs")
+       }
+       if val&mt.NoNodeDefs != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "no_node_defs")
+       }
+       if val&mt.LimitMapRange != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "limit_map_range")
+       }
+       if val&mt.NoPlayerList != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "no_player_list")
+       }
+}
+
+func luaPushHUDFlags(l *lua.State, val mt.HUDFlags) {
+       l.NewTable()
+       if val&mt.ShowHotbar != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "hotbar")
+       }
+       if val&mt.ShowHealthBar != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "health_bar")
+       }
+       if val&mt.ShowCrosshair != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "crosshair")
+       }
+       if val&mt.ShowWieldedItem != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "wielded_item")
+       }
+       if val&mt.ShowBreathBar != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "breath_bar")
+       }
+       if val&mt.ShowMinimap != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "minimap")
+       }
+       if val&mt.ShowRadarMinimap != 0 {
+               l.PushBoolean(true)
+               l.SetField(-2, "radar_minimap")
+       }
+}
+
+func luaPushHUD(l *lua.State, val mt.HUD) {
+       l.NewTable()
+       luaPushVec2(l, [2]float64{float64(val.Align[0]), float64(val.Align[1])})
+       l.SetField(-2, "align")
+       l.PushInteger(int(val.Dir))
+       l.SetField(-2, "dir")
+       l.PushInteger(int(val.Item))
+       l.SetField(-2, "item")
+       l.PushString(string(val.Name))
+       l.SetField(-2, "name")
+       l.PushInteger(int(val.Number))
+       l.SetField(-2, "number")
+       luaPushVec2(l, [2]float64{float64(val.Offset[0]), float64(val.Offset[1])})
+       l.SetField(-2, "offset")
+       luaPushVec2(l, [2]float64{float64(val.Pos[0]), float64(val.Pos[1])})
+       l.SetField(-2, "pos")
+       luaPushVec2(l, [2]float64{float64(val.Scale[0]), float64(val.Scale[1])})
+       l.SetField(-2, "scale")
+       luaPushVec2(l, [2]float64{float64(val.Size[0]), float64(val.Size[1])})
+       l.SetField(-2, "size")
+       l.PushString(string(val.Text))
+       l.SetField(-2, "text")
+       l.PushString(string(val.Text2))
+       l.SetField(-2, "text_2")
+       luaPushHUDType(l, val.Type)
+       l.SetField(-2, "type")
+       luaPushVec3(l, [3]float64{float64(val.WorldPos[0]), float64(val.WorldPos[1]), float64(val.WorldPos[2])})
+       l.SetField(-2, "world_pos")
+       l.PushInteger(int(val.ZIndex))
+       l.SetField(-2, "z_index")
+}
+
+func luaPushNode(l *lua.State, val mt.Node) {
+       l.NewTable()
+       l.PushInteger(int(val.Param0))
+       l.SetField(-2, "param0")
+       l.PushInteger(int(val.Param1))
+       l.SetField(-2, "param1")
+       l.PushInteger(int(val.Param2))
+       l.SetField(-2, "param2")
+}
+
+func luaPushTileAnim(l *lua.State, val mt.TileAnim) {
+       l.NewTable()
+       luaPushVec2(l, [2]float64{float64(val.AspectRatio[0]), float64(val.AspectRatio[1])})
+       l.SetField(-2, "aspect_ratio")
+       l.PushNumber(float64(val.Duration))
+       l.SetField(-2, "duration")
+       luaPushVec2(l, [2]float64{float64(val.NFrames[0]), float64(val.NFrames[1])})
+       l.SetField(-2, "n_frames")
+       luaPushAnimType(l, val.Type)
+       l.SetField(-2, "type")
+}
+
+func pktToString(pkt *mt.Pkt) string {
+       switch pkt.Cmd.(type) {
+       case *mt.ToCltAcceptAuth:
+               return "accept_auth"
+       case *mt.ToCltAcceptSudoMode:
+               return "accept_sudo_mode"
+       case *mt.ToCltAddHUD:
+               return "add_hud"
+       case *mt.ToCltAddNode:
+               return "add_node"
+       case *mt.ToCltAddParticleSpawner:
+               return "add_particle_spawner"
+       case *mt.ToCltAddPlayerVel:
+               return "add_player_vel"
+       case *mt.ToCltAnnounceMedia:
+               return "announce_media"
+       case *mt.ToCltAOMsgs:
+               return "ao_msgs"
+       case *mt.ToCltAORmAdd:
+               return "ao_rm_add"
+       case *mt.ToCltBlkData:
+               return "blk_data"
+       case *mt.ToCltBreath:
+               return "breath"
+       case *mt.ToCltChangeHUD:
+               return "change_hud"
+       case *mt.ToCltChatMsg:
+               return "chat_msg"
+       case *mt.ToCltCloudParams:
+               return "cloud_params"
+       case *mt.ToCltCSMRestrictionFlags:
+               return "csm_restriction_flags"
+       case *mt.ToCltDeathScreen:
+               return "death_screen"
+       case *mt.ToCltDelParticleSpawner:
+               return "del_particle_spawner"
+       case *mt.ToCltDenySudoMode:
+               return "deny_sudo_mode"
+       case *mt.ToCltDetachedInv:
+               return "detached_inv"
+       case *mt.ToCltDisco:
+               return "disco"
+       case *mt.ToCltEyeOffset:
+               return "eye_offset"
+       case *mt.ToCltFadeSound:
+               return "fade_sound"
+       case *mt.ToCltFormspecPrepend:
+               return "formspec_prepend"
+       case *mt.ToCltFOV:
+               return "fov"
+       case *mt.ToCltHello:
+               return "hello"
+       case *mt.ToCltHP:
+               return "hp"
+       case *mt.ToCltHUDFlags:
+               return "hud_flags"
+       case *mt.ToCltInv:
+               return "inv"
+       case *mt.ToCltInvFormspec:
+               return "inv_formspec"
+       case *mt.ToCltItemDefs:
+               return "item_defs"
+       case *mt.ToCltKick:
+               return "kick"
+       case *mt.ToCltLegacyKick:
+               return "legacy_kick"
+       case *mt.ToCltLocalPlayerAnim:
+               return "local_player_anim"
+       case *mt.ToCltMedia:
+               return "media"
+       case *mt.ToCltMediaPush:
+               return "media_push"
+       case *mt.ToCltMinimapModes:
+               return "minimap_modes"
+       case *mt.ToCltModChanMsg:
+               return "mod_chan_msg"
+       case *mt.ToCltModChanSig:
+               return "mod_chan_sig"
+       case *mt.ToCltMoonParams:
+               return "moon_params"
+       case *mt.ToCltMovePlayer:
+               return "move_player"
+       case *mt.ToCltMovement:
+               return "movement"
+       case *mt.ToCltNodeDefs:
+               return "node_defs"
+       case *mt.ToCltNodeMetasChanged:
+               return "node_metas_changed"
+       case *mt.ToCltOverrideDayNightRatio:
+               return "override_day_night_ratio"
+       case *mt.ToCltPlaySound:
+               return "play_sound"
+       case *mt.ToCltPrivs:
+               return "privs"
+       case *mt.ToCltRemoveNode:
+               return "remove_node"
+       case *mt.ToCltRmHUD:
+               return "rm_hud"
+       case *mt.ToCltSetHotbarParam:
+               return "set_hotbar_param"
+       case *mt.ToCltShowFormspec:
+               return "show_formspec"
+       case *mt.ToCltSkyParams:
+               return "sky_params"
+       case *mt.ToCltSpawnParticle:
+               return "spawn_particle"
+       case *mt.ToCltSRPBytesSaltB:
+               return "srp_bytes_salt_b"
+       case *mt.ToCltStarParams:
+               return "star_params"
+       case *mt.ToCltStopSound:
+               return "stop_sound"
+       case *mt.ToCltSunParams:
+               return "sun_params"
+       case *mt.ToCltTimeOfDay:
+               return "time_of_day"
+       case *mt.ToCltUpdatePlayerList:
+               return "update_player_list"
+       }
+       panic("impossible")
+       return ""
+}
+
+func pktToLua(l *lua.State, pkt *mt.Pkt) {
+       if pkt == nil {
+               l.PushNil()
+               return
+       }
+       l.NewTable()
+       l.PushString(pktToString(pkt))
+       l.SetField(-2, "_type")
+       switch val := pkt.Cmd.(type) {
+       case *mt.ToCltAcceptAuth:
+               l.PushNumber(float64(val.MapSeed))
+               l.SetField(-2, "map_seed")
+               luaPushVec3(l, [3]float64{float64(val.PlayerPos[0]), float64(val.PlayerPos[1]), float64(val.PlayerPos[2])})
+               l.SetField(-2, "player_pos")
+               l.PushNumber(float64(val.SendInterval))
+               l.SetField(-2, "send_interval")
+               luaPushAuthMethods(l, val.SudoAuthMethods)
+               l.SetField(-2, "sudo_auth_methods")
+       case *mt.ToCltAddHUD:
+               luaPushHUD(l, val.HUD)
+               l.SetField(-2, "hud")
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+       case *mt.ToCltAddNode:
+               l.PushBoolean(bool(val.KeepMeta))
+               l.SetField(-2, "keep_meta")
+               luaPushNode(l, val.Node)
+               l.SetField(-2, "node")
+               luaPushVec3(l, [3]float64{float64(val.Pos[0]), float64(val.Pos[1]), float64(val.Pos[2])})
+               l.SetField(-2, "pos")
+       case *mt.ToCltAddParticleSpawner:
+               luaPushBox3(l, [2][3]float64{{float64(val.Acc[0][0]), float64(val.Acc[0][1]), float64(val.Acc[0][2])}, {float64(val.Acc[1][0]), float64(val.Acc[1][1]), float64(val.Acc[1][2])}})
+               l.SetField(-2, "acc")
+               l.PushInteger(int(val.Amount))
+               l.SetField(-2, "amount")
+               luaPushTileAnim(l, val.AnimParams)
+               l.SetField(-2, "anim_params")
+               l.PushBoolean(bool(val.AOCollision))
+               l.SetField(-2, "ao_collision")
+               l.PushBoolean(bool(val.Collide))
+               l.SetField(-2, "collide")
+               l.PushBoolean(bool(val.CollisionRm))
+               l.SetField(-2, "collision_rm")
+               l.PushNumber(float64(val.Duration))
+               l.SetField(-2, "duration")
+               luaPushBox1(l, [2]float64{float64(val.ExpirationTime[0]), float64(val.ExpirationTime[1])})
+               l.SetField(-2, "expiration_time")
+               l.PushInteger(int(val.Glow))
+               l.SetField(-2, "glow")
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+               l.PushInteger(int(val.NodeParam0))
+               l.SetField(-2, "node_param0")
+               l.PushInteger(int(val.NodeParam2))
+               l.SetField(-2, "node_param2")
+               l.PushInteger(int(val.NodeTile))
+               l.SetField(-2, "node_tile")
+               luaPushBox3(l, [2][3]float64{{float64(val.Pos[0][0]), float64(val.Pos[0][1]), float64(val.Pos[0][2])}, {float64(val.Pos[1][0]), float64(val.Pos[1][1]), float64(val.Pos[1][2])}})
+               l.SetField(-2, "pos")
+               luaPushBox1(l, [2]float64{float64(val.Size[0]), float64(val.Size[1])})
+               l.SetField(-2, "size")
+               l.PushString(string(val.Texture))
+               l.SetField(-2, "texture")
+               luaPushBox3(l, [2][3]float64{{float64(val.Vel[0][0]), float64(val.Vel[0][1]), float64(val.Vel[0][2])}, {float64(val.Vel[1][0]), float64(val.Vel[1][1]), float64(val.Vel[1][2])}})
+               l.SetField(-2, "vel")
+               l.PushBoolean(bool(val.Vertical))
+               l.SetField(-2, "vertical")
+       case *mt.ToCltAddPlayerVel:
+               luaPushVec3(l, [3]float64{float64(val.Vel[0]), float64(val.Vel[1]), float64(val.Vel[2])})
+               l.SetField(-2, "vel")
+       case *mt.ToCltBlkData:
+               luaPushVec3(l, [3]float64{float64(val.Blkpos[0]), float64(val.Blkpos[1]), float64(val.Blkpos[2])})
+               l.SetField(-2, "blkpos")
+       case *mt.ToCltBreath:
+               l.PushInteger(int(val.Breath))
+               l.SetField(-2, "breath")
+       case *mt.ToCltChangeHUD:
+               if val.Field == mt.HUDAlign {
+                       luaPushVec2(l, [2]float64{float64(val.Align[0]), float64(val.Align[1])})
+                       l.SetField(-2, "align")
+               }
+               if val.Field == mt.HUDDir {
+                       l.PushInteger(int(val.Dir))
+                       l.SetField(-2, "dir")
+               }
+               luaPushHUDField(l, val.Field)
+               l.SetField(-2, "field")
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+               if val.Field == mt.HUDItem {
+                       l.PushInteger(int(val.Item))
+                       l.SetField(-2, "item")
+               }
+               if val.Field == mt.HUDName {
+                       l.PushString(string(val.Name))
+                       l.SetField(-2, "name")
+               }
+               if val.Field == mt.HUDNumber {
+                       l.PushInteger(int(val.Number))
+                       l.SetField(-2, "number")
+               }
+               if val.Field == mt.HUDOffset {
+                       luaPushVec2(l, [2]float64{float64(val.Offset[0]), float64(val.Offset[1])})
+                       l.SetField(-2, "offset")
+               }
+               if val.Field == mt.HUDPos {
+                       luaPushVec2(l, [2]float64{float64(val.Pos[0]), float64(val.Pos[1])})
+                       l.SetField(-2, "pos")
+               }
+               if val.Field == mt.HUDSize {
+                       luaPushVec2(l, [2]float64{float64(val.Size[0]), float64(val.Size[1])})
+                       l.SetField(-2, "size")
+               }
+               if val.Field == mt.HUDText {
+                       l.PushString(string(val.Text))
+                       l.SetField(-2, "text")
+               }
+               if val.Field == mt.HUDText2 {
+                       l.PushString(string(val.Text2))
+                       l.SetField(-2, "text_2")
+               }
+               if val.Field == mt.HUDWorldPos {
+                       luaPushVec3(l, [3]float64{float64(val.WorldPos[0]), float64(val.WorldPos[1]), float64(val.WorldPos[2])})
+                       l.SetField(-2, "world_pos")
+               }
+               if val.Field == mt.HUDZIndex {
+                       l.PushInteger(int(val.ZIndex))
+                       l.SetField(-2, "z_index")
+               }
+       case *mt.ToCltChatMsg:
+               l.PushString(string(val.Sender))
+               l.SetField(-2, "sender")
+               l.PushString(string(val.Text))
+               l.SetField(-2, "text")
+               l.PushNumber(float64(val.Timestamp))
+               l.SetField(-2, "timestamp")
+               luaPushChatMsgType(l, val.Type)
+               l.SetField(-2, "type")
+       case *mt.ToCltCloudParams:
+               luaPushColor(l, val.AmbientColor)
+               l.SetField(-2, "ambient_color")
+               l.PushNumber(float64(val.Density))
+               l.SetField(-2, "density")
+               luaPushColor(l, val.DiffuseColor)
+               l.SetField(-2, "diffuse_color")
+               l.PushNumber(float64(val.Height))
+               l.SetField(-2, "height")
+               luaPushVec2(l, [2]float64{float64(val.Speed[0]), float64(val.Speed[1])})
+               l.SetField(-2, "speed")
+               l.PushNumber(float64(val.Thickness))
+               l.SetField(-2, "thickness")
+       case *mt.ToCltCSMRestrictionFlags:
+               luaPushCSMRestrictionFlags(l, val.Flags)
+               l.SetField(-2, "flags")
+               l.PushInteger(int(val.MapRange))
+               l.SetField(-2, "map_range")
+       case *mt.ToCltDeathScreen:
+               luaPushVec3(l, [3]float64{float64(val.PointAt[0]), float64(val.PointAt[1]), float64(val.PointAt[2])})
+               l.SetField(-2, "point_at")
+               l.PushBoolean(bool(val.PointCam))
+               l.SetField(-2, "point_cam")
+       case *mt.ToCltDelParticleSpawner:
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+       case *mt.ToCltDetachedInv:
+               l.PushString(string(val.Inv))
+               l.SetField(-2, "inv")
+               l.PushBoolean(bool(val.Keep))
+               l.SetField(-2, "keep")
+               l.PushInteger(int(val.Len))
+               l.SetField(-2, "len")
+               l.PushString(string(val.Name))
+               l.SetField(-2, "name")
+       case *mt.ToCltEyeOffset:
+               luaPushVec3(l, [3]float64{float64(val.First[0]), float64(val.First[1]), float64(val.First[2])})
+               l.SetField(-2, "first")
+               luaPushVec3(l, [3]float64{float64(val.Third[0]), float64(val.Third[1]), float64(val.Third[2])})
+               l.SetField(-2, "third")
+       case *mt.ToCltFadeSound:
+               l.PushNumber(float64(val.Gain))
+               l.SetField(-2, "gain")
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+               l.PushNumber(float64(val.Step))
+               l.SetField(-2, "step")
+       case *mt.ToCltFormspecPrepend:
+               l.PushString(string(val.Prepend))
+               l.SetField(-2, "prepend")
+       case *mt.ToCltFOV:
+               l.PushNumber(float64(val.FOV))
+               l.SetField(-2, "fov")
+               l.PushBoolean(bool(val.Multiplier))
+               l.SetField(-2, "multiplier")
+               l.PushNumber(float64(val.TransitionTime))
+               l.SetField(-2, "transition_time")
+       case *mt.ToCltHello:
+               luaPushAuthMethods(l, val.AuthMethods)
+               l.SetField(-2, "auth_methods")
+               l.PushInteger(int(val.Compression))
+               l.SetField(-2, "compression")
+               l.PushInteger(int(val.ProtoVer))
+               l.SetField(-2, "proto_ver")
+               l.PushInteger(int(val.SerializeVer))
+               l.SetField(-2, "serialize_ver")
+               l.PushString(string(val.Username))
+               l.SetField(-2, "username")
+       case *mt.ToCltHP:
+               l.PushInteger(int(val.HP))
+               l.SetField(-2, "hp")
+       case *mt.ToCltHUDFlags:
+               luaPushHUDFlags(l, val.Flags)
+               l.SetField(-2, "flags")
+               luaPushHUDFlags(l, val.Mask)
+               l.SetField(-2, "mask")
+       case *mt.ToCltInv:
+               l.PushString(string(val.Inv))
+               l.SetField(-2, "inv")
+       case *mt.ToCltInvFormspec:
+               l.PushString(string(val.Formspec))
+               l.SetField(-2, "formspec")
+       case *mt.ToCltKick:
+               if dr := val.Reason; dr == mt.Custom || dr == mt.Shutdown || dr == mt.Crash {
+                       l.PushString(string(val.Custom))
+                       l.SetField(-2, "custom")
+               }
+               luaPushKickReason(l, val.Reason)
+               l.SetField(-2, "reason")
+               if dr := val.Reason; dr == mt.Shutdown || dr == mt.Crash {
+                       l.PushBoolean(bool(val.Reconnect))
+                       l.SetField(-2, "reconnect")
+               }
+       case *mt.ToCltLegacyKick:
+               l.PushString(string(val.Reason))
+               l.SetField(-2, "reason")
+       case *mt.ToCltLocalPlayerAnim:
+               luaPushBox1(l, [2]float64{float64(val.Dig[0]), float64(val.Dig[1])})
+               l.SetField(-2, "dig")
+               luaPushBox1(l, [2]float64{float64(val.Idle[0]), float64(val.Idle[1])})
+               l.SetField(-2, "idle")
+               l.PushNumber(float64(val.Speed))
+               l.SetField(-2, "speed")
+               luaPushBox1(l, [2]float64{float64(val.Walk[0]), float64(val.Walk[1])})
+               l.SetField(-2, "walk")
+               luaPushBox1(l, [2]float64{float64(val.WalkDig[0]), float64(val.WalkDig[1])})
+               l.SetField(-2, "walk_dig")
+       case *mt.ToCltMediaPush:
+               l.PushString(string(val.Data))
+               l.SetField(-2, "data")
+               l.PushString(string(val.Filename))
+               l.SetField(-2, "filename")
+               l.PushString(string(val.SHA1[:]))
+               l.SetField(-2, "sha1")
+               l.PushBoolean(bool(val.ShouldCache))
+               l.SetField(-2, "should_cache")
+       case *mt.ToCltModChanMsg:
+               l.PushString(string(val.Channel))
+               l.SetField(-2, "channel")
+               l.PushString(string(val.Msg))
+               l.SetField(-2, "msg")
+               l.PushString(string(val.Sender))
+               l.SetField(-2, "sender")
+       case *mt.ToCltModChanSig:
+               l.PushString(string(val.Channel))
+               l.SetField(-2, "channel")
+               luaPushModChanSig(l, val.Signal)
+               l.SetField(-2, "signal")
+       case *mt.ToCltMoonParams:
+               l.PushNumber(float64(val.Size))
+               l.SetField(-2, "size")
+               l.PushString(string(val.Texture))
+               l.SetField(-2, "texture")
+               l.PushString(string(val.ToneMap))
+               l.SetField(-2, "tone_map")
+               l.PushBoolean(bool(val.Visible))
+               l.SetField(-2, "visible")
+       case *mt.ToCltMovePlayer:
+               l.PushNumber(float64(val.Pitch))
+               l.SetField(-2, "pitch")
+               luaPushVec3(l, [3]float64{float64(val.Pos[0]), float64(val.Pos[1]), float64(val.Pos[2])})
+               l.SetField(-2, "pos")
+               l.PushNumber(float64(val.Yaw))
+               l.SetField(-2, "yaw")
+       case *mt.ToCltMovement:
+               l.PushNumber(float64(val.AirAccel))
+               l.SetField(-2, "air_accel")
+               l.PushNumber(float64(val.ClimbSpeed))
+               l.SetField(-2, "climb_speed")
+               l.PushNumber(float64(val.CrouchSpeed))
+               l.SetField(-2, "crouch_speed")
+               l.PushNumber(float64(val.DefaultAccel))
+               l.SetField(-2, "default_accel")
+               l.PushNumber(float64(val.FastAccel))
+               l.SetField(-2, "fast_accel")
+               l.PushNumber(float64(val.FastSpeed))
+               l.SetField(-2, "fast_speed")
+               l.PushNumber(float64(val.Fluidity))
+               l.SetField(-2, "fluidity")
+               l.PushNumber(float64(val.Gravity))
+               l.SetField(-2, "gravity")
+               l.PushNumber(float64(val.JumpSpeed))
+               l.SetField(-2, "jump_speed")
+               l.PushNumber(float64(val.Sink))
+               l.SetField(-2, "sink")
+               l.PushNumber(float64(val.Smoothing))
+               l.SetField(-2, "smoothing")
+               l.PushNumber(float64(val.WalkSpeed))
+               l.SetField(-2, "walk_speed")
+       case *mt.ToCltOverrideDayNightRatio:
+               l.PushBoolean(bool(val.Override))
+               l.SetField(-2, "override")
+               l.PushInteger(int(val.Ratio))
+               l.SetField(-2, "ratio")
+       case *mt.ToCltPlaySound:
+               l.PushBoolean(bool(val.Ephemeral))
+               l.SetField(-2, "ephemeral")
+               l.PushNumber(float64(val.Fade))
+               l.SetField(-2, "fade")
+               l.PushNumber(float64(val.Gain))
+               l.SetField(-2, "gain")
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+               l.PushBoolean(bool(val.Loop))
+               l.SetField(-2, "loop")
+               l.PushString(string(val.Name))
+               l.SetField(-2, "name")
+               l.PushNumber(float64(val.Pitch))
+               l.SetField(-2, "pitch")
+               luaPushVec3(l, [3]float64{float64(val.Pos[0]), float64(val.Pos[1]), float64(val.Pos[2])})
+               l.SetField(-2, "pos")
+               l.PushInteger(int(val.SrcAOID))
+               l.SetField(-2, "src_aoid")
+               luaPushSoundSrcType(l, val.SrcType)
+               l.SetField(-2, "src_type")
+       case *mt.ToCltPrivs:
+               luaPushStringSet(l, val.Privs)
+               l.SetField(-2, "privs")
+       case *mt.ToCltRemoveNode:
+               luaPushVec3(l, [3]float64{float64(val.Pos[0]), float64(val.Pos[1]), float64(val.Pos[2])})
+               l.SetField(-2, "pos")
+       case *mt.ToCltRmHUD:
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+       case *mt.ToCltSetHotbarParam:
+               l.PushString(string(val.Img))
+               l.SetField(-2, "img")
+               luaPushHotbarParam(l, val.Param)
+               l.SetField(-2, "param")
+               l.PushInteger(int(val.Size))
+               l.SetField(-2, "size")
+       case *mt.ToCltShowFormspec:
+               l.PushString(string(val.Formname))
+               l.SetField(-2, "formname")
+               l.PushString(string(val.Formspec))
+               l.SetField(-2, "formspec")
+       case *mt.ToCltSkyParams:
+               luaPushColor(l, val.BgColor)
+               l.SetField(-2, "bg_color")
+               l.PushBoolean(bool(val.Clouds))
+               l.SetField(-2, "clouds")
+               if val.Type == "regular" {
+                       luaPushColor(l, val.DawnHorizon)
+                       l.SetField(-2, "dawn_horizon")
+               }
+               if val.Type == "regular" {
+                       luaPushColor(l, val.DawnSky)
+                       l.SetField(-2, "dawn_sky")
+               }
+               if val.Type == "regular" {
+                       luaPushColor(l, val.DayHorizon)
+                       l.SetField(-2, "day_horizon")
+               }
+               if val.Type == "regular" {
+                       luaPushColor(l, val.DaySky)
+                       l.SetField(-2, "day_sky")
+               }
+               l.PushString(string(val.FogTintType))
+               l.SetField(-2, "fog_tint_type")
+               if val.Type == "regular" {
+                       luaPushColor(l, val.Indoor)
+                       l.SetField(-2, "indoor")
+               }
+               luaPushColor(l, val.MoonFogTint)
+               l.SetField(-2, "moon_fog_tint")
+               if val.Type == "regular" {
+                       luaPushColor(l, val.NightHorizon)
+                       l.SetField(-2, "night_horizon")
+               }
+               if val.Type == "regular" {
+                       luaPushColor(l, val.NightSky)
+                       l.SetField(-2, "night_sky")
+               }
+               luaPushColor(l, val.SunFogTint)
+               l.SetField(-2, "sun_fog_tint")
+               if val.Type == "skybox" {
+                       luaPushTextureList(l, val.Textures)
+                       l.SetField(-2, "textures")
+               }
+               l.PushString(string(val.Type))
+               l.SetField(-2, "type")
+       case *mt.ToCltSpawnParticle:
+               luaPushVec3(l, [3]float64{float64(val.Acc[0]), float64(val.Acc[1]), float64(val.Acc[2])})
+               l.SetField(-2, "acc")
+               luaPushTileAnim(l, val.AnimParams)
+               l.SetField(-2, "anim_params")
+               l.PushBoolean(bool(val.AOCollision))
+               l.SetField(-2, "ao_collision")
+               l.PushBoolean(bool(val.Collide))
+               l.SetField(-2, "collide")
+               l.PushBoolean(bool(val.CollisionRm))
+               l.SetField(-2, "collision_rm")
+               l.PushNumber(float64(val.ExpirationTime))
+               l.SetField(-2, "expiration_time")
+               l.PushInteger(int(val.Glow))
+               l.SetField(-2, "glow")
+               l.PushInteger(int(val.NodeParam0))
+               l.SetField(-2, "node_param0")
+               l.PushInteger(int(val.NodeParam2))
+               l.SetField(-2, "node_param2")
+               l.PushInteger(int(val.NodeTile))
+               l.SetField(-2, "node_tile")
+               luaPushVec3(l, [3]float64{float64(val.Pos[0]), float64(val.Pos[1]), float64(val.Pos[2])})
+               l.SetField(-2, "pos")
+               l.PushNumber(float64(val.Size))
+               l.SetField(-2, "size")
+               l.PushString(string(val.Texture))
+               l.SetField(-2, "texture")
+               luaPushVec3(l, [3]float64{float64(val.Vel[0]), float64(val.Vel[1]), float64(val.Vel[2])})
+               l.SetField(-2, "vel")
+               l.PushBoolean(bool(val.Vertical))
+               l.SetField(-2, "vertical")
+       case *mt.ToCltSRPBytesSaltB:
+               l.PushString(string(val.B))
+               l.SetField(-2, "b")
+               l.PushString(string(val.Salt))
+               l.SetField(-2, "salt")
+       case *mt.ToCltStarParams:
+               luaPushColor(l, val.Color)
+               l.SetField(-2, "color")
+               l.PushInteger(int(val.Count))
+               l.SetField(-2, "count")
+               l.PushNumber(float64(val.Size))
+               l.SetField(-2, "size")
+               l.PushBoolean(bool(val.Visible))
+               l.SetField(-2, "visible")
+       case *mt.ToCltStopSound:
+               l.PushInteger(int(val.ID))
+               l.SetField(-2, "id")
+       case *mt.ToCltSunParams:
+               l.PushString(string(val.Rise))
+               l.SetField(-2, "rise")
+               l.PushBoolean(bool(val.Rising))
+               l.SetField(-2, "rising")
+               l.PushNumber(float64(val.Size))
+               l.SetField(-2, "size")
+               l.PushString(string(val.Texture))
+               l.SetField(-2, "texture")
+               l.PushString(string(val.ToneMap))
+               l.SetField(-2, "tone_map")
+               l.PushBoolean(bool(val.Visible))
+               l.SetField(-2, "visible")
+       case *mt.ToCltTimeOfDay:
+               l.PushNumber(float64(val.Speed))
+               l.SetField(-2, "speed")
+               l.PushInteger(int(val.Time))
+               l.SetField(-2, "time")
+       case *mt.ToCltUpdatePlayerList:
+               luaPushStringList(l, val.Players)
+               l.SetField(-2, "players")
+               luaPushPlayerListUpdateType(l, val.Type)
+               l.SetField(-2, "type")
+       }
+}
index d49d46deaa17094e60ce1d9067b869b0c96fa9e2..1141991c8f5c60b1f13e71207893c1fcc27cfc81 100755 (executable)
@@ -1,4 +1,37 @@
 #!/usr/bin/env lua
+local function snext(t, state)
+       local key
+
+       if state == nil then
+               t.__sorted = {}
+               for k in pairs(t) do
+                       if k ~= "__sorted" then
+                               table.insert(t.__sorted, k)
+                       end
+               end
+               table.sort(t.__sorted)
+               
+               key = t.__sorted[1]
+       else
+               for i, v in ipairs(t.__sorted) do
+                       if v == state then
+                               key = t.__sorted[i + 1]
+                               break
+                       end
+               end
+       end
+
+       if key then
+               return key, t[key]
+       end
+
+       t.__sorted = nil
+end
+
+local function spairs(t)
+       return snext, t, nil
+end
+
 local function parse_pair(pair, value_first)
        if pair:sub(1, 1) == "#" then
                return
@@ -73,7 +106,7 @@ end
 
 local funcs = ""
 
-for name, fields in pairs(parse_spec("client/enum")) do
+for name, fields in spairs(parse_spec("client/enum")) do
        local camel = camel_case(name)
        funcs = funcs .. "func luaPush" .. camel .. "(l *lua.State, val mt." .. camel .. ") {\n\tswitch val {\n"
 
@@ -86,7 +119,7 @@ for name, fields in pairs(parse_spec("client/enum")) do
        funcs = funcs .. "\t}\n}\n\n"
 end
 
-for name, fields in pairs(parse_spec("client/flag")) do
+for name, fields in spairs(parse_spec("client/flag")) do
        local camel = camel_case(name)
        funcs = funcs .. "func luaPush" .. camel .. "(l *lua.State, val mt." .. camel .. ") {\n\tl.NewTable()\n"
 
@@ -115,7 +148,7 @@ local push_type = {
 local function push_fields(fields, indent)
        local impl = ""
        
-       for name, type in pairs(fields) do
+       for name, type in spairs(fields) do
                if name:sub(1, 1) ~= "[" then
                        local camel = "val." .. camel_case(name)
 
@@ -144,7 +177,7 @@ local function push_fields(fields, indent)
        return impl
 end
 
-for name, fields in pairs(parse_spec("client/struct", true)) do
+for name, fields in spairs(parse_spec("client/struct", true)) do
        local camel = camel_case(name)
        funcs = funcs
                .. "func luaPush" .. camel .. "(l *lua.State, val mt." .. camel .. ") {\n\tl.NewTable()\n"
@@ -155,7 +188,7 @@ end
 local to_string_impl = ""
 local to_lua_impl = ""
 
-for name, fields in pairs(parse_spec("client/pkt", true)) do
+for name, fields in spairs(parse_spec("client/pkt", true)) do
        local case = "\tcase *mt.ToClt" .. camel_case(name) .. ":\n"
 
        to_string_impl = to_string_impl