Hello all,
I need to create a textfile from inside an external and I need to give the computer a path with a message like:
path /home/path/file.txt
I am therefore creating a method for path with:
class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_GIMME, 0);
Or should I use A_DEFSYMBOL ?
But then how can I read the atom inside the external?
I am using:
void testtext_path(t_testtext *x, t_atom *s){ char teststring[1000]; atom_string(s, teststring, 1000); post(teststring); }
but then I get the following printout:
consistency check failed: atom_string 333333@ÿÿÿÿs
I'm not sure where to move with this. anybody has any suggestions?
best,
J
Here's the info for atom_string: atom_string
void atom_string(t_atom *a, char *buf, unsigned int bufsize); Converts an atom a into a C-string buf. The memory to this char-Buffer has to be reserved manually and its length has to be declared in bufsize.
in: http://pdstatic.iem.at/externals-HOWTO/node9.html#SECTION0009220000000000000...
Hi Jaime -
If you use A_GIMME the function prototype has to be as in:
void testtext_path(t_testtext *x, t_symbol *s, int argc, t_atom *argv).
cheers Miller
On Sun, May 19, 2013 at 10:47:20PM -0500, J Oliver wrote:
Hello all,
I need to create a textfile from inside an external and I need to give the computer a path with a message like:
path /home/path/file.txt
I am therefore creating a method for path with:
class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_GIMME, 0);
Or should I use A_DEFSYMBOL ?
But then how can I read the atom inside the external?
I am using:
void testtext_path(t_testtext *x, t_atom *s){ char teststring[1000]; atom_string(s, teststring, 1000); post(teststring); }
but then I get the following printout:
consistency check failed: atom_string 333333@ÿÿÿÿs
I'm not sure where to move with this. anybody has any suggestions?
best,
J
Here's the info for atom_string: atom_string
void atom_string(t_atom *a, char *buf, unsigned int bufsize); Converts an atom a into a C-string buf. The memory to this char-Buffer has to be reserved manually and its length has to be declared in bufsize.
in: http://pdstatic.iem.at/externals-HOWTO/node9.html#SECTION0009220000000000000...
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
of course!!
thanks,
J
void testtext_path(t_testtext *x, t_symbol *s, int argc, t_atom *argv) { char teststring[1000]; atom_string(argv, teststring, 1000); post(teststring); }
On May 19, 2013, at 11:28 PM, Miller Puckette wrote:
Hi Jaime -
If you use A_GIMME the function prototype has to be as in:
void testtext_path(t_testtext *x, t_symbol *s, int argc, t_atom *argv).
cheers Miller
On Sun, May 19, 2013 at 10:47:20PM -0500, J Oliver wrote:
Hello all,
I need to create a textfile from inside an external and I need to give the computer a path with a message like:
path /home/path/file.txt
I am therefore creating a method for path with:
class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_GIMME, 0);
Or should I use A_DEFSYMBOL ?
But then how can I read the atom inside the external?
I am using:
void testtext_path(t_testtext *x, t_atom *s){ char teststring[1000]; atom_string(s, teststring, 1000); post(teststring); }
but then I get the following printout:
consistency check failed: atom_string 333333@ÿÿÿÿs
I'm not sure where to move with this. anybody has any suggestions?
best,
J
Here's the info for atom_string: atom_string
void atom_string(t_atom *a, char *buf, unsigned int bufsize); Converts an atom a into a C-string buf. The memory to this char-Buffer has to be reserved manually and its length has to be declared in bufsize.
in: http://pdstatic.iem.at/externals-HOWTO/node9.html#SECTION0009220000000000000...
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 05/19/2013 11:47 PM, J Oliver wrote:
Hello all,
I need to create a textfile from inside an external and I need to give the computer a path with a message like:
path /home/path/file.txt
I am therefore creating a method for path with:
class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_GIMME, 0);
Or should I use A_DEFSYMBOL ?
I'd use A_DEFSYMBOL if you want the user to be able to send a "path" message with no args, and A_SYMBOL if you want to require them to specify some path.
But then how can I read the atom inside the external?
I am using:
void testtext_path(t_testtext *x, t_atom *s){ char teststring[1000]; atom_string(s, teststring, 1000); post(teststring); }
but then I get the following printout:
consistency check failed: atom_string 333333@ÿÿÿÿs
I'm not sure where to move with this. anybody has any suggestions?
I don't have time to check it but I'd imagine the problem is that A_GIMME assumes the method wants the following args: t_testtext*, t_symbol*, int, and a t_atom*
where the t_symbol* refers to the selector that was used to call the method-- in this case, the word "path". (That can come in handy, btw, as you can have methods "chocolate" and "vanilla" point to the same foo_icecream function and branch based on which selector was used.)
However, you only specified two arguments for that method, and one of them is t_atom* so I guess it implicitly casts from the t_symbol* it receives. (I think the compiler warns you about stuff like this but I'm no expert so maybe I'm wrong.)
Then inside atom_string (in m_atom.c) it switches based on a->a_type,
but your "a" doesn't have an a_type because it's really a t_symbol*.
Thus none of the cases match and so the function ends up calling the
"bug" function that prints out the error you see.
Essentially you tried to build a string using a reference to an atom that's not really an atom, so Pd complained that you weren't being consistent.
-Jonathan
best,
J
Here's the info for atom_string:
atom_string
void atom_string(t_atom *a, char *buf, unsigned int bufsize); Converts an atom |a| into a C-string |buf|. The memory to this char-Buffer has to be reserved manually and its length has to be declared in |bufsize|.
in: http://pdstatic.iem.at/externals-HOWTO/node9.html#SECTION0009220000000000000...
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 05/20/2013 05:47 AM, J Oliver wrote:
Hello all,
I need to create a textfile from inside an external and I need to give the computer a path with a message like:
path /home/path/file.txt
I am therefore creating a method for path with:
class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_GIMME, 0);
Or should I use A_DEFSYMBOL ?
the A_GIMME part being covered by miller, i wanted to add that really the way to go is to use Pd's stringish type for a path: a symbol. the difference between A_DEFSYMBOL and A_SYMBOL is that the former allows the user to *not* specify a symbol, whereas with A_SYMBOL the argument is mandatory. since the "path" method doesn't make much sense without a path, i'd go for:
<snip> static void tettext_path(t_testtext*x, t_symbol*s) { /* ... */ }
//... class_addmethod(testtext_class, (t_method)testtext_path, gensym("path"), A_SYMBOL, A_NULL);
</snip>
also note that the terminating ", 0" is fine as long as you use a C-compiler, but if you try compiling with a reasonable strict C++-compiler, it might tell you to use ", A_NULL" instead.
gfasdr IOhannes