![]() |
![]() |
![]() |
Cattle Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <cattle/cattle.h> struct CattleProgram; CattleProgram * cattle_program_new (void
); gboolean cattle_program_load (CattleProgram *program
,const gchar *string
,GError **error
); void cattle_program_set_instructions (CattleProgram *program
,CattleInstruction *instructions
); CattleInstruction * cattle_program_get_instructions (CattleProgram *program
); void cattle_program_set_input (CattleProgram *program
,const gchar *input
); gchar * cattle_program_get_input (CattleProgram *program
);
A CattleProgram represents a complete Brainfuck program, that is, the instructions to be executed and possibly its input.
The input for a program can optionally be specified in the source file, and it's separated from the program code by a bang (!) symbol. For example, given the following input:
1 |
,+.!sometext |
the program's code is ",+." while the program's input is "sometext".
Any Brainfuck instruction after the bang symbol is considered part of the input, and as such is not executed. Subsequent bang symbols are also considered part of the input.
struct CattleProgram;
Opaque data structure representing a program. It should never be accessed directly; use the methods below instead.
CattleProgram * cattle_program_new (void
);
Create a new CattleProgram.
A single instance of a program can be shared between multiple interpreters, as long as the object is not modified after it has been initialized.
Returns : |
a new CattleProgram. [transfer full] |
gboolean cattle_program_load (CattleProgram *program
,const gchar *string
,GError **error
);
Load program
from string
.
The string can optionally contain also the input for the program: in that case, the input must be separated from the code by a bang (!) character.
In case of failure, error
is filled with detailed information.
The error domain is CATTLE_ERROR
, and the error code is from the
CattleError enumeration.
|
a CattleProgram |
|
the source code of the program |
|
return location for a GError. [allow-none] |
Returns : |
TRUE on success, FALSE otherwise |
void cattle_program_set_instructions (CattleProgram *program
,CattleInstruction *instructions
);
Set the instructions for program
.
You shouldn't usually need to use this: see cattle_program_load()
for the standard way to load a program.
|
a CattleProgram |
|
instructions for program
|
CattleInstruction * cattle_program_get_instructions (CattleProgram *program
);
Get the instructions for program
.
See cattle_program_load()
and cattle_program_set_instructions()
.
|
a CattleProgram |
Returns : |
the first instruction in program . [transfer full]
|
void cattle_program_set_input (CattleProgram *program
,const gchar *input
);
Set the input for program
.
If input
is NULL
, the input will be retrieved at runtime.
|
a CattleProgram |
|
input for program , or NULL . [allow-none]
|
gchar * cattle_program_get_input (CattleProgram *program
);
Get the input for program
.
See cattle_program_set_input()
.
|
a CattleProgram |
Returns : |
input for program , or NULL . [transfer full]
|
"input"
property"input" gchar* : Read / Write
Input for the program, or NULL
if no input was available
at the time of loading.
Changes to this property are not notified.
Default value: NULL
"instructions"
property"instructions" CattleInstruction* : Read / Write
Instructions for the program.
Changes to this property are not notified.