I am getting a syntax error of Unexpected '(' from the following code:
object o = Stdio.File("filepath", "wct+");
if(o) { o->write("foo");
o->close(); }
the syntax error comes from the o->write("foo"); line. I have tried multiple variations of this and nothing works. Although in Hilfe it works. If I change it from write to Write it also compiles but then it does not write the data. I am currently running 7.6.50.
--------------------------------- Yahoo! Photos Got holiday prints? See all the ways to get quality prints in your hands ASAP.
"Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se wrote: You need to put your code inside a function. Try calling it "main". Well I was hoping that would be assumed.
But maybe me posting the whole bit of code will help...
void handle_error(array|object trace, void|object o) { if(mixed x=catch {
object ferr = Stdio.File("C:/EMAGE/sys/data/log/run.c", "wca+");
string sWrite = describe_backtrace(trace);
int nLine; string sFunc; string sFile; string sParams; string sOut = "";
if(o) { sOut += "Error occured in: " + object_name(o) + "\n"; }
foreach(sWrite/"\n", string s) { if(sscanf(s, "%s:%d:%*s->%s(%s", sFile, nLine, sFunc, sParams) == 5) { string sLine = (string)nLine; string sTemp = " ";
sLine = sTemp[0 .. sizeof(sTemp) - sizeof(sLine)] + sLine + " "; sTemp = " "; sFunc = sFunc + sTemp[0 .. sizeof(sTemp) - sizeof(sFunc)];
sOut += sLine + sFunc + sFile + " (" + sParams + ")\n"; } else { if(s != "") { sOut += s + "\t" + ctime(time()); } } }
sOut += "\n";
ferr->Write(sOut); }) { // One reason for this might be too little stack space, which // easily can occur for "out of stack" errors. It should help to // tune up the STACK_MARGIN values in interpret.c then. werror("Error in handle_error in master object:\n"); if(catch { catch { if (catch { string msg = [string]x[0]; werror("%s", msg); array bt = [array]x[1]; werror("%O\n", bt); }) { werror("%O\n", x); } }; werror("Original error:\n" "%O\n", trace); }) { werror("sprintf() failed to write error.\n"); } } }
now this is inside a modified master.pike. The code has worked on previous versions of pike. So not sure why it does not work now.
--------------------------------- Yahoo! Photos Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
"Martin Nilsson (Opera) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se wrote: > object ferr = Stdio.File("C:/EMAGE/sys/data/log/run.c", "wca+");
ferr->Write(sOut);
I don't think there is a Write method in Stdio.File. It doesn't work either way for me. The only way I can get it to compile is with Write. If I change it to the way it is documented on the site as write it won't even compile. That is when I get the syntax error.
--------------------------------- Yahoo! Photos Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
works here (7.6.50), if i replace "object_name(o)" by something defined, and ->Write by ->write.
after calling handle_error(backtrace(), this); the created file reads:
Error occured in: duh 70 main some.pike ())
now this is inside a modified master.pike. The code has worked on
^^^^^^^^^^^^^^^^^^^^
previous versions of pike. So not sure why it does not work now.
Ok, there's probably the cause of the problem. In Pike 7.4 and 7.6's default master.pike there's the following #define's:
#define write(X ...) _static_modules.files()->_stdout->write(X)
#define write(X ...) (Files()->_stdout->write(X))
(In Pike 7.7 the #define has been replaced with a variable).
pike-devel@lists.lysator.liu.se