saving generators
This commit is contained in:
parent
641f38f295
commit
f3ff4f5755
|
|
@ -0,0 +1,3 @@
|
|||
pub const c = @cImport({ // todo, should not be constant
|
||||
@cInclude("SDL3/SDL.h");
|
||||
});
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
import os
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
import subprocess
|
||||
|
||||
origDir = os.path.abspath(os.path.dirname(__file__))
|
||||
os.chdir(origDir)
|
||||
|
||||
gpufile = "../../SDL/include/SDL3/SDL_gpu.h"
|
||||
|
||||
mode_default = 0
|
||||
mode_collecting = 1
|
||||
|
||||
typedefs_pod = []
|
||||
typedefs_opaque = []
|
||||
typedefs_enum = []
|
||||
typedefs_struct = []
|
||||
typedefs_unknown = []
|
||||
|
||||
functions = []
|
||||
|
||||
defines = []
|
||||
|
||||
lastList = None
|
||||
|
||||
with open(gpufile) as f:
|
||||
mode = mode_default
|
||||
braceCount = 0
|
||||
for l in f:
|
||||
dropped = True
|
||||
line = l.strip()
|
||||
if mode == mode_default:
|
||||
if line.startswith('typedef'):
|
||||
if ";" in line and 'struct' in line:
|
||||
typedefs_opaque.append(line)
|
||||
dropped = False
|
||||
elif ';' in line:
|
||||
typedefs_pod.append(line)
|
||||
dropped = False
|
||||
elif 'enum' in line:
|
||||
lastList = typedefs_enum
|
||||
typedefs_enum.append(line)
|
||||
dropped = False
|
||||
elif 'struct' in line:
|
||||
lastList = typedefs_struct
|
||||
typedefs_struct.append(line)
|
||||
dropped = False
|
||||
else:
|
||||
lastList = typedefs_unknown
|
||||
dropped = False
|
||||
typedefs_unknown.append(line)
|
||||
|
||||
elif line.startswith('extern SDL_DECLSPEC'):
|
||||
lastList = functions
|
||||
dropped = False
|
||||
functions.append(line)
|
||||
|
||||
elif line.startswith('#define '):
|
||||
lastList = defines
|
||||
defines.append(line)
|
||||
|
||||
if ';' not in line and not dropped:
|
||||
mode = mode_collecting
|
||||
if "{" in l:
|
||||
braceCount = 1
|
||||
|
||||
elif mode == mode_collecting:
|
||||
lastList[-1] += l.replace('\n', '\n')
|
||||
|
||||
if "{" in line:
|
||||
braceCount += 1
|
||||
|
||||
if "}" in line:
|
||||
braceCount -= 1
|
||||
|
||||
if ';' in line and braceCount == 0:
|
||||
mode = mode_default
|
||||
|
||||
print_types = False
|
||||
print_functions = False
|
||||
print_defines= False
|
||||
|
||||
def plos(l):
|
||||
for s in l:
|
||||
print('> ', s, " < ")
|
||||
|
||||
print('opaque')
|
||||
plos(typedefs_opaque)
|
||||
print('pod')
|
||||
plos(typedefs_pod)
|
||||
if print_types:
|
||||
print('struct')
|
||||
plos(typedefs_struct)
|
||||
print('enum')
|
||||
plos(typedefs_enum)
|
||||
print('unknown')
|
||||
plos(typedefs_unknown)
|
||||
|
||||
if print_functions:
|
||||
print('functions')
|
||||
plos(functions)
|
||||
|
||||
if print_defines:
|
||||
print('defines')
|
||||
plos(defines)
|
||||
|
||||
print(f"\nfunctions: {len(functions)}, structs:{len(typedefs_struct)}, enums:{len(typedefs_enum)}\n")
|
||||
|
||||
ostring = 'pub const c = @import("c.zig").c;\n\n'
|
||||
# time to generate types...
|
||||
# first the opaques
|
||||
|
||||
typeMap = {}
|
||||
typeMap_r= {}
|
||||
|
||||
for t in typedefs_opaque:
|
||||
c_typename = t.strip().strip(';').split(' ')[3]
|
||||
typename = c_typename
|
||||
|
||||
if typename.startswith("SDL_"):
|
||||
typename = typename[4:]
|
||||
|
||||
typeMap[c_typename] = typename
|
||||
typeMap_r[typename] = c_typename
|
||||
|
||||
brackets = "{}"
|
||||
definition = f"pub const {typename} = opaque{brackets};\n"
|
||||
ostring += definition
|
||||
print (ostring)
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
const c = @import("c.zig").c;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
pub const c = @cImport({ // todo, should not be constant
|
||||
@cInclude("SDL3/SDL.h");
|
||||
});
|
||||
|
||||
pub const InitOptions = packed struct(c_int) {
|
||||
pad0: u4 = 0, // 0 - 3
|
||||
audio: bool = false, // 4
|
||||
video: bool = false, // 5
|
||||
pad1: u2 = 0, // 6-7
|
||||
pad2: u1 = 0, // 8
|
||||
joystick: bool = false, // 9
|
||||
pad3: u2 = 0, // 10-11
|
||||
haptic: bool = false, // 12
|
||||
gamepad: bool = false,
|
||||
events: bool = false,
|
||||
sensor: bool = false,
|
||||
camera: bool = false,
|
||||
pad4: u3 = 0,
|
||||
pad5: u12 = 0,
|
||||
};
|
||||
|
||||
pub const AppResult = enum{
|
||||
app_continue,
|
||||
app_success,
|
||||
app_failure,
|
||||
};
|
||||
|
||||
pub const Window = opaque {};
|
||||
|
||||
pub fn createWindow() !*Window {
|
||||
|
||||
return @ptrCast();
|
||||
}
|
||||
|
||||
pub fn init(options: InitOptions) !void {
|
||||
if (!c.SDL_Init(@bitCast(options))) {
|
||||
return error.InitFailed;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +1,4 @@
|
|||
pub const c = @cImport({ // todo, should not be constant
|
||||
@cInclude("SDL3/SDL.h");
|
||||
});
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const InitOptions = packed struct(c_int) {
|
||||
// nibble 0
|
||||
pad0: u4 = 0, // 0 - 3
|
||||
|
||||
// nibble 1
|
||||
audio: bool = false, // 4
|
||||
video: bool = false, // 5
|
||||
pad1: u2 = 0, // 6-7
|
||||
|
||||
// nibble 2
|
||||
pad2: u1 = 0, // 8
|
||||
joystick: bool = false, // 9
|
||||
pad3: u2 = 0, // 10-11
|
||||
|
||||
// nibble 3
|
||||
haptic: bool = false, // 12
|
||||
gamepad: bool = false,
|
||||
events: bool = false,
|
||||
sensor: bool = false,
|
||||
|
||||
// nibble 4
|
||||
camera: bool = false,
|
||||
pad4: u3 = 0,
|
||||
|
||||
pad5: u12 = 0,
|
||||
};
|
||||
|
||||
pub const Window = opaque {};
|
||||
|
||||
pub fn createWindow() !*Window {}
|
||||
|
||||
pub fn init(options: InitOptions) !void {
|
||||
if (!c.SDL_Init(@bitCast(options))) {
|
||||
return error.InitFailed;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pollEvent() ?c.SDL_Event {
|
||||
var event: c.SDL_Event = undefined;
|
||||
|
||||
if (c.SDL_PollEvent(&event)) {
|
||||
return event;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
pub const SDLEvent = struct {};
|
||||
|
||||
pub const SDL_CommonEvent = struct {
|
||||
eventType: u32 = 0, // Event type, shared with all events,
|
||||
reserved: u32 = 0,
|
||||
timestamp: u64 = 0, // in nanoseconds, populated using SDL_GetTickNS()
|
||||
};
|
||||
pub const gpu = @import("gpu.zig");
|
||||
pub const init = @import("init.zig");
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
const c = @import("c.zig").c;
|
||||
Loading…
Reference in New Issue