added variables (struct + setters)
This commit is contained in:
parent
635bb8c16e
commit
1c3e7e7c00
@ -191,6 +191,55 @@ def main():
|
|||||||
|
|
||||||
variables["EVENTS_EMITS_DEC"] = "\n\n".join(events_emits_dec)
|
variables["EVENTS_EMITS_DEC"] = "\n\n".join(events_emits_dec)
|
||||||
|
|
||||||
|
#############
|
||||||
|
# Variables #
|
||||||
|
#############
|
||||||
|
|
||||||
|
vars_init = []
|
||||||
|
vars_struct = []
|
||||||
|
vars_setters_def = []
|
||||||
|
vars_setters_dec = []
|
||||||
|
|
||||||
|
setter_def = ""
|
||||||
|
setter_def += "void {filename}_set{Name}({filename}* me, {type} v) {\n"
|
||||||
|
setter_def += " me->{name} = v;\n"
|
||||||
|
setter_def += "}"
|
||||||
|
setter_def = setter_def.replace("{filename}", variables["filename"])
|
||||||
|
|
||||||
|
setter_dec = "void {filename}_set{Name}({filename}* me, {type} v);"
|
||||||
|
setter_dec = setter_dec.replace("{filename}", variables["filename"])
|
||||||
|
|
||||||
|
print("Variables:")
|
||||||
|
print("(leave name empty to end)")
|
||||||
|
while True:
|
||||||
|
name = input("Name: ").strip()
|
||||||
|
if not name: break
|
||||||
|
|
||||||
|
type_ = input("Type: ").strip()
|
||||||
|
default = input("Default value: ").strip()
|
||||||
|
print()
|
||||||
|
|
||||||
|
vars_struct.append(f"{type_} {name};")
|
||||||
|
|
||||||
|
if default:
|
||||||
|
vars_init.append(f"me->{name} = {default};")
|
||||||
|
|
||||||
|
vars_setters_def.append(
|
||||||
|
setter_def.replace("{type}", type_)
|
||||||
|
.replace("{name}", name)
|
||||||
|
.replace("{Name}", ucfirst(name))
|
||||||
|
)
|
||||||
|
|
||||||
|
vars_setters_dec.append(
|
||||||
|
setter_dec.replace("{type}", type_)
|
||||||
|
.replace("{Name}", ucfirst(name))
|
||||||
|
)
|
||||||
|
|
||||||
|
variables["VARS_INIT"] = "\n".join(vars_init)
|
||||||
|
variables["VARS_STRUCT"] = "\n".join(vars_struct)
|
||||||
|
variables["VARS_SETTERS_DEF"] = "\n\n".join(vars_setters_def)
|
||||||
|
variables["VARS_SETTERS_DEC"] = "\n\n".join(vars_setters_dec)
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# Fill templates #
|
# Fill templates #
|
||||||
##################
|
##################
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
void ${filename}_init(${filename}* me){
|
void ${filename}_init(${filename}* me){
|
||||||
me->state = ST${fn}_INIT;
|
me->state = ST${fn}_INIT;
|
||||||
|
${VARS_INIT}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ${filename}_startBehaviour(${filename}* me){
|
void ${filename}_startBehaviour(${filename}* me){
|
||||||
@ -52,4 +53,10 @@ bool ${filename}_processEvent(Event* ev) {
|
|||||||
* EMITTERS *
|
* EMITTERS *
|
||||||
************/
|
************/
|
||||||
|
|
||||||
${EVENTS_EMITS_DEF}
|
${EVENTS_EMITS_DEF}
|
||||||
|
|
||||||
|
/***********
|
||||||
|
* SETTERS *
|
||||||
|
***********/
|
||||||
|
|
||||||
|
${VARS_SETTERS_DEF}
|
@ -19,6 +19,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
${filename}_STATES state;
|
${filename}_STATES state;
|
||||||
|
${VARS_STRUCT}
|
||||||
} ${filename};
|
} ${filename};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,4 +47,10 @@ bool ${filename}_processEvent(Event* ev);
|
|||||||
|
|
||||||
${EVENTS_EMITS_DEC}
|
${EVENTS_EMITS_DEC}
|
||||||
|
|
||||||
|
/***********
|
||||||
|
* SETTERS *
|
||||||
|
***********/
|
||||||
|
|
||||||
|
${VARS_SETTERS_DEC}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user