|
@@ -24,6 +24,7 @@ module_names = {
|
|
'slog_': 'log',
|
|
'slog_': 'log',
|
|
'sg_': 'gfx',
|
|
'sg_': 'gfx',
|
|
'sapp_': 'app',
|
|
'sapp_': 'app',
|
|
|
|
+ 'sargs_': 'args',
|
|
'stm_': 'time',
|
|
'stm_': 'time',
|
|
'saudio_': 'audio',
|
|
'saudio_': 'audio',
|
|
'sgl_': 'gl',
|
|
'sgl_': 'gl',
|
|
@@ -32,6 +33,7 @@ module_names = {
|
|
'sglue_': 'glue',
|
|
'sglue_': 'glue',
|
|
'sfetch_': 'fetch',
|
|
'sfetch_': 'fetch',
|
|
'simgui_': 'imgui',
|
|
'simgui_': 'imgui',
|
|
|
|
+ 'snk_': 'nuklear',
|
|
'smemtrack_': 'memtrack',
|
|
'smemtrack_': 'memtrack',
|
|
}
|
|
}
|
|
|
|
|
|
@@ -39,6 +41,7 @@ c_source_paths = {
|
|
'slog_': 'sokol-d/src/sokol/c/sokol_log.c',
|
|
'slog_': 'sokol-d/src/sokol/c/sokol_log.c',
|
|
'sg_': 'sokol-d/src/sokol/c/sokol_gfx.c',
|
|
'sg_': 'sokol-d/src/sokol/c/sokol_gfx.c',
|
|
'sapp_': 'sokol-d/src/sokol/c/sokol_app.c',
|
|
'sapp_': 'sokol-d/src/sokol/c/sokol_app.c',
|
|
|
|
+ 'sargs_': 'sokol-d/src/sokol/c/sokol_args.c',
|
|
'stm_': 'sokol-d/src/sokol/c/sokol_time.c',
|
|
'stm_': 'sokol-d/src/sokol/c/sokol_time.c',
|
|
'saudio_': 'sokol-d/src/sokol/c/sokol_audio.c',
|
|
'saudio_': 'sokol-d/src/sokol/c/sokol_audio.c',
|
|
'sgl_': 'sokol-d/src/sokol/c/sokol_gl.c',
|
|
'sgl_': 'sokol-d/src/sokol/c/sokol_gl.c',
|
|
@@ -47,6 +50,7 @@ c_source_paths = {
|
|
'sglue_': 'sokol-d/src/sokol/c/sokol_glue.c',
|
|
'sglue_': 'sokol-d/src/sokol/c/sokol_glue.c',
|
|
'sfetch_': 'sokol-d/src/sokol/c/sokol_fetch.c',
|
|
'sfetch_': 'sokol-d/src/sokol/c/sokol_fetch.c',
|
|
'simgui_': 'sokol-d/src/sokol/c/sokol_imgui.c',
|
|
'simgui_': 'sokol-d/src/sokol/c/sokol_imgui.c',
|
|
|
|
+ 'snk_': 'sokol-d/src/sokol/c/sokol_nuklear.c',
|
|
'smemtrack_': 'sokol-d/src/sokol/c/sokol_memtrack.c',
|
|
'smemtrack_': 'sokol-d/src/sokol/c/sokol_memtrack.c',
|
|
}
|
|
}
|
|
|
|
|
|
@@ -56,7 +60,8 @@ ignores = [
|
|
]
|
|
]
|
|
|
|
|
|
c_callbacks = [
|
|
c_callbacks = [
|
|
- 'slog_func'
|
|
|
|
|
|
+ 'slog_func',
|
|
|
|
+ 'nk_plugin_filter',
|
|
]
|
|
]
|
|
|
|
|
|
overrides = {
|
|
overrides = {
|
|
@@ -77,6 +82,9 @@ overrides = {
|
|
'sdtx_font.font_index': 'uint32_t',
|
|
'sdtx_font.font_index': 'uint32_t',
|
|
'SGL_NO_ERROR': 'SGL_ERROR_NO_ERROR',
|
|
'SGL_NO_ERROR': 'SGL_ERROR_NO_ERROR',
|
|
'sfetch_continue': 'continue_fetching',
|
|
'sfetch_continue': 'continue_fetching',
|
|
|
|
+ 'struct nk_context': 'NkContext',
|
|
|
|
+ 'nk_handle': 'NkHandle',
|
|
|
|
+ 'nk_flags': 'NkFlags',
|
|
}
|
|
}
|
|
|
|
|
|
prim_types = {
|
|
prim_types = {
|
|
@@ -123,10 +131,26 @@ class TypeConverter:
|
|
self.enum_types = enum_types
|
|
self.enum_types = enum_types
|
|
|
|
|
|
def as_d_type(self, c_type, is_param=False, decl_name=None):
|
|
def as_d_type(self, c_type, is_param=False, decl_name=None):
|
|
|
|
+ c_type = c_type.strip()
|
|
|
|
+ # Check for override first
|
|
|
|
+ if c_type in overrides:
|
|
|
|
+ return overrides[c_type]
|
|
|
|
+
|
|
d_to_c_types = {v: k for k, v in prim_types.items()}
|
|
d_to_c_types = {v: k for k, v in prim_types.items()}
|
|
if c_type in d_to_c_types:
|
|
if c_type in d_to_c_types:
|
|
c_type = d_to_c_types[c_type]
|
|
c_type = d_to_c_types[c_type]
|
|
|
|
|
|
|
|
+ # Handle struct keyword in type (e.g., "struct nk_context *")
|
|
|
|
+ if c_type.startswith('struct '):
|
|
|
|
+ c_type = c_type[7:].strip() # Remove 'struct' prefix
|
|
|
|
+ if c_type in overrides:
|
|
|
|
+ return overrides[c_type]
|
|
|
|
+ if c_type.endswith('*'):
|
|
|
|
+ # External struct pointer, treat as opaque
|
|
|
|
+ return 'void*' if is_param else 'void*'
|
|
|
|
+ # External struct by value, treat as named type if overridden
|
|
|
|
+ return overrides.get(c_type, c_type)
|
|
|
|
+
|
|
if util.is_func_ptr(c_type):
|
|
if util.is_func_ptr(c_type):
|
|
return self.as_func_ptr_type(c_type, decl_name)
|
|
return self.as_func_ptr_type(c_type, decl_name)
|
|
|
|
|
|
@@ -167,6 +191,14 @@ class TypeConverter:
|
|
if util.is_array_type(c_type):
|
|
if util.is_array_type(c_type):
|
|
return self.as_array_type(c_type)
|
|
return self.as_array_type(c_type)
|
|
|
|
|
|
|
|
+ # Handle external types (e.g., nk_handle, nk_flags) not in struct_types or prim_types
|
|
|
|
+ if c_type not in self.struct_types and c_type not in prim_types:
|
|
|
|
+ if c_type.endswith('*'):
|
|
|
|
+ # Treat pointer to unknown type as void*
|
|
|
|
+ return 'void*' if is_param else 'void*'
|
|
|
|
+ # Treat unknown type by value as itself (assuming it's defined elsewhere)
|
|
|
|
+ return overrides.get(c_type, c_type)
|
|
|
|
+
|
|
raise ValueError(f"Unsupported C type: {c_type} in declaration: {decl_name or 'unknown'}")
|
|
raise ValueError(f"Unsupported C type: {c_type} in declaration: {decl_name or 'unknown'}")
|
|
|
|
|
|
def as_d_struct_type(self, s):
|
|
def as_d_struct_type(self, s):
|
|
@@ -274,6 +306,17 @@ def pre_parse(inp):
|
|
enum_types.append(enum_name)
|
|
enum_types.append(enum_name)
|
|
enum_items[enum_name] = [as_enum_item_name(item['name']) for item in decl['items']]
|
|
enum_items[enum_name] = [as_enum_item_name(item['name']) for item in decl['items']]
|
|
|
|
|
|
|
|
+def gen_nuklear_types():
|
|
|
|
+ """Generate type declarations for Nuklear external types."""
|
|
|
|
+ l("/++ Nuklear external type declarations +/")
|
|
|
|
+ l("extern(C) struct NkContext;")
|
|
|
|
+ l("extern(C) union NkHandle {")
|
|
|
|
+ l(" void* ptr;")
|
|
|
|
+ l(" int id;")
|
|
|
|
+ l("}")
|
|
|
|
+ l("alias NkFlags = uint;")
|
|
|
|
+ l("alias nk_plugin_filter = extern(C) int function(const(NkContext)*, NkHandle, int*, int) @system @nogc nothrow;")
|
|
|
|
+
|
|
def gen_struct(decl, type_converter):
|
|
def gen_struct(decl, type_converter):
|
|
struct_name = overrides.get(decl['name'], decl['name'])
|
|
struct_name = overrides.get(decl['name'], decl['name'])
|
|
d_type = type_converter.as_d_struct_type(struct_name)
|
|
d_type = type_converter.as_d_struct_type(struct_name)
|
|
@@ -417,6 +460,9 @@ def gen_module(inp, dep_prefixes, c_header_path):
|
|
l(f'module sokol.{inp["module"]};')
|
|
l(f'module sokol.{inp["module"]};')
|
|
logging.info(f"Generating imports for module {inp['module']}")
|
|
logging.info(f"Generating imports for module {inp['module']}")
|
|
gen_imports(inp, dep_prefixes)
|
|
gen_imports(inp, dep_prefixes)
|
|
|
|
+ # Add Nuklear types for the nuklear module
|
|
|
|
+ if inp['module'] == 'nuklear':
|
|
|
|
+ gen_nuklear_types()
|
|
pre_parse(inp)
|
|
pre_parse(inp)
|
|
type_converter = TypeConverter(inp['prefix'], struct_types, enum_types)
|
|
type_converter = TypeConverter(inp['prefix'], struct_types, enum_types)
|
|
for decl in inp['decls']:
|
|
for decl in inp['decls']:
|