if you create a file in /opt/Bela/local/bela_startup.sh (and make it executable), it will be called at boot with the PROJECT and ARGS (and I think BELA_HOME) variables set. You can then use it to call your file:
#!/bin/bash
cd $BELA_HOME/projects/$PROJECT
while sleep 0.1; do
LAST=$?
./$PROJECT $ARGS -f $LAST
done
where $? contains the exit code of the last command. To retrieve the value of the command-line option -f you should use provide a main.cpp file and use a procedure similar to the one used in, e.g.: example Extras/userData, to parse that variable in main() and pass it to setup() (and render() and cleanup()) via the void* userData pointer. Alternatively, easier but less elegant, you can set an environment variable before calling the program and access it via getenv(), e.g.:
#!/bin/bash
cd $BELA_HOME/projects/$PROJECT
while sleep 0.1; do
export LAST=$?
./$PROJECT $ARGS
done
then in C++ (untested):
// at the top
#include <stdlibg.h>
...
// in setup()
int last = 0; // default value if LAST is not defined
const char* lastStr = getenv("LAST");
if(lastStr)
last = atoi(lastStr);