Exemplo n.º 1
0
def gen(c_header_path, c_prefix, dep_c_prefixes):
    global out_lines
    module_name = module_names[c_prefix]
    c_source_path = c_source_paths[c_prefix]
    print(f'  {c_header_path} => {module_name}')
    reset_globals()
    shutil.copyfile(c_header_path, f'sokol-nim/src/sokol/c/{os.path.basename(c_header_path)}')
    ir = gen_ir.gen(c_header_path, c_source_path, module_name, c_prefix, dep_c_prefixes)
    gen_module(ir, dep_c_prefixes)
    output_path = f"sokol-nim/src/sokol/{ir['module']}.nim"

    ## some changes for readability
    out_lines = out_lines.replace("PixelformatInfo", "PixelFormatInfo")
    out_lines = out_lines.replace(" Dontcare,", " DontCare,")
    out_lines = out_lines.replace(" Vertexbuffer,", " VertexBuffer,")
    out_lines = out_lines.replace(" Indexbuffer,", " IndexBuffer,")
    out_lines = out_lines.replace(" N2d,", " Plane,")
    out_lines = out_lines.replace(" N3d,", " Volume,")
    out_lines = out_lines.replace(" Vs,", " Vertex,")
    out_lines = out_lines.replace(" Fs,", " Fragment,")

    ## include extensions in generated code
    l("# Nim-specific API extensions")
    l(f"include ext/{ir['module']}")

    ## copy extensions into generated code
    # ext_path = f"sokol-nim/src/sokol/ext/{ir['module']}.nim"
    # if os.path.isfile(ext_path):
    #     with open(ext_path, 'r') as f_ext:
    #         out_lines += f_ext.read()

    with open(output_path, 'w', newline='\n') as f_outp:
        f_outp.write(out_lines)
Exemplo n.º 2
0
def gen(c_header_path, c_prefix, dep_c_prefixes):
    module_name = module_names[c_prefix]
    c_source_path = c_source_paths[c_prefix]
    print(f'  {c_header_path} => {module_name}')
    reset_globals()
    shutil.copyfile(c_header_path, f'sokol-zig/src/sokol/c/{os.path.basename(c_header_path)}')
    ir = gen_ir.gen(c_header_path, c_source_path, module_name, c_prefix, dep_c_prefixes)
    gen_module(ir, dep_c_prefixes)
    output_path = f"sokol-zig/src/sokol/{ir['module']}.zig"
    with open(output_path, 'w', newline='\n') as f_outp:
        f_outp.write(out_lines)
Exemplo n.º 3
0
def gen(c_header_path, c_prefix, dep_c_prefixes):
    if not c_prefix in module_names:
        print(f'warning: skipping generation for {c_prefix} prefix...')
        return
    global out_lines
    module_name = module_names[c_prefix]
    c_source_path = c_source_paths[c_prefix]
    print(f'  {c_header_path} => {module_name}')
    reset_globals()
    shutil.copyfile(
        c_header_path,
        f'sokol-nim/src/sokol/c/{os.path.basename(c_header_path)}')
    ir = gen_ir.gen(c_header_path, c_source_path, module_name, c_prefix,
                    dep_c_prefixes)
    gen_module(ir, dep_c_prefixes)
    output_path = f"sokol-nim/src/sokol/{ir['module']}.nim"
    with open(output_path, 'w', newline='\n') as f_outp:
        f_outp.write(out_lines)
Exemplo n.º 4
0
import gen_ir, gen_zig

tasks = [['../sokol_gfx.h', 'sg_', 'gfx'], ['../sokol_app.h', 'sapp_', 'app'],
         ['../sokol_time.h', 'stm_', 'time']]

# Zig
print('> generating Zig bindings...')
gen_zig.prepare()
for task in tasks:
    c_header_path = task[0]
    c_prefix = task[1]
    module_name = task[2]
    print(f'  {c_header_path} => {module_name}.zig')
    ir = gen_ir.gen(c_header_path, module_name, c_prefix)
    gen_zig.gen(c_header_path, ir)
Exemplo n.º 5
0
import gen_ir, gen_zig

tasks = [['../sokol_gfx.h', 'sg_', 'gfx'], ['../sokol_app.h', 'sapp_', 'app'],
         ['../sokol_time.h', 'stm_', 'time'],
         ['../sokol_audio.h', 'saudio_', 'audio']]

# Zig
print('> generating Zig bindings...')
gen_zig.prepare()
for task in tasks:
    c_header_path = task[0]
    c_prefix = task[1]
    module_name = task[2]
    print(f'  {c_header_path} => {module_name}.zig')
    ir = gen_ir.gen(c_header_path, module_name, c_prefix,
                    ["-DSOKOL_ZIG_BINDINGS"])
    gen_zig.gen(c_header_path, ir)