Skip to content

Instantly share code, notes, and snippets.

@DorianRudolph
Created May 1, 2024 13:31
Show Gist options
  • Save DorianRudolph/1be46b909764faa5559673936342bc3f to your computer and use it in GitHub Desktop.
Save DorianRudolph/1be46b909764faa5559673936342bc3f to your computer and use it in GitHub Desktop.
Create symbol table for native.rs of pdfium-render
import re
with open("src/native.rs") as f:
s = f.read()
s = s.split("fn extern_")[1:]
struct = []
construct = []
def process(s):
name = "extern_" + s.split("(")[0]
typ = s.split("Symbol<")[1].split('>,')[0]
typ = re.sub(r'\s+', ' ', typ).replace(', )', ')').strip().rstrip(',')
symbol_name = s.split('.get(')[1].split(')')[0]
struct.append(f'{name}: {typ}')
construct.append(f'{name}: *(library.get({symbol_name})?)')
for x in s:
process(x)
print(',\n'.join(struct))
print('\n\n')
print(',\n'.join(construct))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment