[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Noob needs help with examples/foreachq
From: |
Jeff Barnes |
Subject: |
Noob needs help with examples/foreachq |
Date: |
Wed, 24 Aug 2011 07:54:40 -0700 (PDT) |
Need help with foreachq. My M4PATH includes the foreachq.m4 file.
$ cat mystatemachine.m4
statemachine(mystatemachine,
events(
),
states(
state(`State1', `State1', `composite', `State1_START',
deep_h_transitions(
deep_h_transition(`State1')
)
),
state(`State4', `State1_State4', `normal', `0',
deep_h_transitions(
deep_h_transition(`State1')
deep_h_transition(`State4')
)
)
),
transitions(
transition(
State4_Playing1,
from_states(
from_state(`State4'),
from_state(`State1')
),
to_states(
to_state(`State2'),
to_state(`Playing1')
),
transitionEvent(`my_event'),
transitionAction(`myaction'),
dest(`NORMAL_DEST')
)
)
)
$ cat init_trans_from_states
include(`foreachq.m4')
define(statemachine,`
#include "statemachine.h"
#include "$1.h"
void
init_trans_from_states(void) {
$2 $3 $4
}
')
define(events,`')
define(event,`')
define(states, `')
define(transitions,`foreachq(`x', `$@', x)')
define(transition,`
$1->fromStates = { `$2' };')
define(from_states, `foreachq(`y', `$@', y )')
define(from_state, `$1')
include(`mystatemachine.m4')
$ m4 init_trans_from_states_c.m4
#include "statemachine.h"
#include "mystatemachine.h"
void
init_trans_from_states(void) {
State4_Playing1->fromStates = { State4 State1
};
}
So far so good. Now I want to put a comma between them, so I redefine the
from_states rule to be:
define(from_states, `foreachq(`y', `$@', y`, ')')
Then,
$ m4 init_trans_from_states_c.m4
#include "statemachine.h"
#include "mystatemachine.h"
void
init_trans_from_states(void) {
State4_Playing1->fromStates = { State4 };
}
Hmmm, what happened to State1? I know I'll need to do a counter or something to
eventually not add an extra comma, but now it seems the $@ isn't right.
Any help appreciated.
Jeff Barnes
- Noob needs help with examples/foreachq,
Jeff Barnes <=