-
Notifications
You must be signed in to change notification settings - Fork 4
Script meta programming scratch
Menooker edited this page Oct 23, 2018
·
3 revisions
C++: 100+ LOC?
Birdee:
class tuple[T... as class]
{@
i=0
for type in T:
class_body(f"public v{i} as {type}")
@}
end
tuple[int,long] is
class tuple
public v0 as int
public v1 as int
end
C++: hard/ugly - invasive solutions
Java: runtime reflection - overhead
Birdee:
function obj2json[T](obj as T) as string
dim js as json=new json
{@
for field in T.fields:
expr(f"js.add_key_value('{field.name}',obj.{field.name})")
@}
return js.getstring()
end
{{
#python function
#generates getter/setters for each private fields
def gen_get_set():
selfclass=get_current_class()
for field in selfclass.fields:
type=field.type
if field.access==AccessModifier.PRIVATE:
class_body(f'''
public function get_{field}() as {type}
return {field}
end
public function set_{field}(f as {type})
{field}=f
end
''')
}}
class SomeDataClass
private a as int
private b as string
#I have 100 fields
{{
gen_get_set() ##auto generate getters & setters
}}
end
C++: ???
Java: annotation, reflection - overhead
Birdee: ...