From 71dc5a4288f2d77334b8b8dc8ce33a1171aa044b Mon Sep 17 00:00:00 2001
From: Leonid Emar-Kar <lemarkar@flightpath3d.com>
Date: Tue, 17 Dec 2024 16:48:52 +0000
Subject: [PATCH] add snakecase conversion for struct fields in genStructInit

---
 bind/gen_struct.go | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/bind/gen_struct.go b/bind/gen_struct.go
index b50ddfc..9fd358a 100644
--- a/bind/gen_struct.go
+++ b/bind/gen_struct.go
@@ -70,6 +70,16 @@ in which case a new Go object is constructed first
 		if _, err := isPyCompatField(f); err != nil {
 			continue
 		}
+
+		gname := f.Name()
+		if g.cfg.RenameCase {
+			gname = toSnakeCase(gname)
+		}
+
+		if newName, err := extractPythonNameFieldTag(gname, s.Struct().Tag(i)); err == nil {
+			gname = newName
+		}
+
 		// NOTE: this will accept int args for any handles / object fields so
 		// some kind of additional type-checking logic to prevent that in a way
 		// that also allows valid handles to be used as required. This is
@@ -79,11 +89,11 @@ in which case a new Go object is constructed first
 		// etc can be assigned to directly.
 		g.pywrap.Printf("if  %[1]d < len(args):\n", i)
 		g.pywrap.Indent()
-		g.pywrap.Printf("self.%s = args[%d]\n", f.Name(), i)
+		g.pywrap.Printf("self.%s = args[%d]\n", gname, i)
 		g.pywrap.Outdent()
-		g.pywrap.Printf("if %[1]q in kwargs:\n", f.Name())
+		g.pywrap.Printf("if %[1]q in kwargs:\n", gname)
 		g.pywrap.Indent()
-		g.pywrap.Printf("self.%[1]s = kwargs[%[1]q]\n", f.Name())
+		g.pywrap.Printf("self.%[1]s = kwargs[%[1]q]\n", gname)
 		g.pywrap.Outdent()
 	}
 	g.pywrap.Outdent()