Thank you! I am away now, but I will try all of your solutions on monday! :-)
2014-11-28 22:30 GMT+01:00 Jon Harper <jon.harpe...@gmail.com>: > After investigating a bit, it might be possible? If someone more > knowledgeable about the ffi could comment on the following: > > FUNCTION: char* strcpy ( char * , c-string ) ; > : foo ( -- ) { { { char 2 } initial: B{ 0x41 0 } } } [ "B" strcpy drop ] > with-out-parameters utf8 alien>string print ; > : bar ( -- ) { { { char 2 } initial: B{ 0x41 0 } } } [ drop ] > with-out-parameters utf8 alien>string print ; > > foo ! prints "B" > bar ! prints "A" > > If there is no syntactic sugar yet for passing strings with > with-out-parameters, it might be interesting to add it I guess > > PS: typed this manually, sorry if there are typos :) > Jon > > Le 28 nov. 2014 20:43, "Jon Harper" <jon.harpe...@gmail.com> a écrit : > >> John provided an alternative, but here are the explanations of the errors >> you got: >> >> On Fri, Nov 28, 2014 at 5:14 PM, Andrea Ferretti >> <ferrettiand...@gmail.com> wrote: >>> >>> { { c-string } } [ "hello world" swap example_cp ] with-out-parameters >> >> The syntax of with-out-parameters is an array of elements, which are >> either a c-type, or a triple { c-type intial: value }. So in your case, it >> should have been >> { c-string } [ "hello world" swap example_cp ] with-out-parameters >> >>> I get "index out of bounds: 0" which seems reasonable, since I pass an >>> empty c-string. But if I try something like >>> >>> { { c-string initial: "hello earth" } } [ "hello world" swap >>> example_cp ] with-out-parameters >>> >>> I get "local-allocation-error". >> >> The FFI only works with the optimizing compiler, so this code should be >> defined in a word, not run in the interactive listener. You can define the >> word in a source file, or directly in the listener and then call it just >> after you defined it >> >> >> Cheers, >> Jon > > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk > _______________________________________________ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk