Skip to content

Instantly share code, notes, and snippets.

@Tillsten
Created March 5, 2019 15:51
NiceLib skeleton generator
# Generates a skeleton for a nicelib NiceLib and NiceObj from
# parsing the argnames dict of the low-level bindings
def gen_binding(argnames, libname, objname=None, prefix='',
handlename='instrumentHandle', file=sys.stdout):
p = lambda x: print(x, file=file)
indent = ' '
class_lines = []
obj_lines = []
for name, arg in argnames.items():
name = name.lstrip(prefix)
info_line = '# ' + ' '.join(arg)
sig = 'Sig(%s)'%('\'in\','*len(arg))
line = f'{name} = {sig}'
if not arg[0] == handlename:
class_lines += [info_line, line]
else:
obj_lines += [info_line, line]
p(f'class {libname}(NiceLib):')
for i in class_lines:
p(indent+i)
if objname and len(obj_lines) > 0:
p(indent + f'class {objname}(NiceObject):')
for i in obj_lines:
p(2*indent + i)
#example call
gen_binding(argnames, 'DFMlib', objname='DeformableMirror', prefix='TLDFM_',
file=open('bla.py', 'w'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment