The idea of interfaces is kind of like structs but for functions (only). So for example you could have something like:
con
%interface winio(
pubputs(p_str)pubnewline()
)
pubmyfunc(^winio w)
w.puts(@"hello, world")
w.newline()
Then any object which implements the puts and newline methods can be passed to the myfunc method.
I have a tentative implementation for Spin2 checked in to github now, but it's probably buggy. We could also change the way it works a bit, if there are shortcomings we find now.
Ah man that is fantastic That worked straight away...That's a nice simple syntax and I think it really fills a good space between function pointers and object pointers.
Thanks a million!
Very strange because the code compiles fine. This is with latest release.
Doesn't like this line: _setbaud(2_000_000)
Gives this error: /Propeller2/9DOF/teapot_demo3_2/teapot_demo3_2_wIMU2.spin2:93: error: unknown identifier _setbaud used in function call
error: Unable to write file padmap_builtin.dat to zip
child process exited abnormally
The setbaud error is spurious (I've fixed it in github, but it won't prevent a .zip file from being created). The real problem is on the next line:
error: Unable to write file padmap_builtin.dat to zip
it's missing a file that's referred to in the source code. As it happens in your configuration that file isn't needed (it's inside an if clause that's false) so you can work around it by creating an empty file named padmap_builtin.dat, or else comment out the file "padmap_builtin.dat" line in usbnew.zip.
This is WAI -- if you want to distribute a zip file which contains conditional parts, it's actually reasonable to check that all of the conditional parts are there. Otherwise if the receiver changes their configuration then they won't be able to build.
(Unfortunately this is inconsistent between if and #ifdef, because the preprocessor runs before everything else and erases the #ifdef'd parts so the zip file processor never even gets to see them. That is a bug, but it's hard to fix. So for now, at least, if you really don't want to package the whole thing, use #ifdef on the parts you don't have.)
@Wuerfel_21 said:
But in this case it's a user-supplied file, it doesn't exist if it doesn't need to.
Then maybe there should be a sample one, or an empty one, in the archive as shipped. Or use #ifdef around the file statement instead of if.
@Rayman said:
Could it just make the zip and issue any warning messages it wants to?
If it can't find a file that's supposed to be included in the zip that seems like a potential recipe for disaster. It's good in some cases (when the file deliberately isn't present, as in Ada's example) but bad if the user really did mean to have the file but forgot to copy it to somewhere flexspin can find it.
Think the Prop Tool will only create a zip file if the main file can compile (or was compiled? not sure, but one of those). Maybe that check is good enough?
The file not neccesarily being present is a feature, I think most people do not want a zero-byte file related to a gamepad mapping feature that may not even be compiled in at all cluttering up their project dir.
Comments
The idea of interfaces is kind of like structs but for functions (only). So for example you could have something like:
con %interface winio( pub puts(p_str) pub newline() ) pub myfunc(^winio w) w.puts(@"hello, world") w.newline()
Then any object which implements the
puts
andnewline
methods can be passed to themyfunc
method.I have a tentative implementation for Spin2 checked in to github now, but it's probably buggy. We could also change the way it works a bit, if there are shortcomings we find now.
Ah man that is fantastic
That worked straight away...That's a nice simple syntax and I think it really fills a good space between function pointers and object pointers.
Thanks a million!
Getting a strange error when trying to create a .zip archive, described here: https://forums.parallax.com/discussion/176083/3d-teapot-demo#latest
Very strange because the code compiles fine. This is with latest release.
Doesn't like this line: _setbaud(2_000_000)
Gives this error:
/Propeller2/9DOF/teapot_demo3_2/teapot_demo3_2_wIMU2.spin2:93: error: unknown identifier _setbaud used in function call
error: Unable to write file padmap_builtin.dat to zip
child process exited abnormally
The setbaud error is spurious (I've fixed it in github, but it won't prevent a .zip file from being created). The real problem is on the next line:
error: Unable to write file padmap_builtin.dat to zip
it's missing a file that's referred to in the source code. As it happens in your configuration that file isn't needed (it's inside an
if
clause that's false) so you can work around it by creating an empty file namedpadmap_builtin.dat
, or else comment out thefile "padmap_builtin.dat"
line in usbnew.zip.I already complained about this. https://github.com/totalspectrum/spin2cpp/issues/450
Strange behaviors when trying to make zip files.
This is WAI -- if you want to distribute a zip file which contains conditional parts, it's actually reasonable to check that all of the conditional parts are there. Otherwise if the receiver changes their configuration then they won't be able to build.
(Unfortunately this is inconsistent between
if
and#ifdef
, because the preprocessor runs before everything else and erases the#ifdef
'd parts so the zip file processor never even gets to see them. That is a bug, but it's hard to fix. So for now, at least, if you really don't want to package the whole thing, use#ifdef
on the parts you don't have.)But in this case it's a user-supplied file, it doesn't exist if it doesn't need to.
Could it just make the zip and issue any warning messages it wants to?
Then maybe there should be a sample one, or an empty one, in the archive as shipped. Or use
#ifdef
around thefile
statement instead ofif
.If it can't find a file that's supposed to be included in the zip that seems like a potential recipe for disaster. It's good in some cases (when the file deliberately isn't present, as in Ada's example) but bad if the user really did mean to have the file but forgot to copy it to somewhere flexspin can find it.
Think the Prop Tool will only create a zip file if the main file can compile (or was compiled? not sure, but one of those). Maybe that check is good enough?
Can't be #ifdef because it's CON configuration.
The file not neccesarily being present is a feature, I think most people do not want a zero-byte file related to a gamepad mapping feature that may not even be compiled in at all cluttering up their project dir.