World: r4wp
[#Red] Red language group
older newer | first last |
Andreas 30-Jun-2013 [9089] | https://github.com/blog/1529-repository-next |
DocKimbel 30-Jun-2013 [9090] | Thanks. The right position for the menu is a bit annoying, but I guess we'll get used to it...Still I prefer the previous layout. |
Arnold 1-Jul-2013 [9091] | Not every change is an improvement |
Bo 1-Jul-2013 [9092x4] | OK. I have this snippet of Red/System code that is giving me an access violation. I can't seem to find why: dirs-file: as-c-string 64 dirs-file: "to-process/dirs.txt" dirs: as-c-string 1024 dirs: read-file dirs-file ;'dirs now contains the contents of %to-process/dirs.txt eol: as-c-string 1024 eol: find-char dirs #"^/" ;Finds the first end-of-line character line-len: as-integer eol - dirs print-line line-len ;In my example, this returns 24, which is correct first-line: as-c-string (line-len + 1) ;An extra byte for #"^(00)" to be safe copy-string-part first-line dirs as-integer eol - dirs ;Access violation. Why? |
In the above example, dirs.txt is a text file of size 524 bytes. | |
Just in case it had a problem with me not picking up the return c-string from copy-string-part, I added a line and changed the last line, so the end should look like this: return-string: as-c-string 1024 return-string: copy-string-part first-line dirs as-integer eol - dirs ;Access violation. Why? | |
Same results. | |
Kaj 1-Jul-2013 [9096x4] | Same thing as before with binary pointers |
as-c-string 64 | |
gives you a pointer to memory address 64, which is invalid | |
I see I have the argument order inconsistent between copy-part and copy-string-part. I've corrected that in the binding, so you now have to swap the arguments | |
Bo 1-Jul-2013 [9100x2] | Thanks, Kaj. Sometimes it feels like it will be forever before I'm comfortable with Red/System. |
Is there really a [size!] datatype in Red/System? Is that the same as [integer!]? | |
Kaj 1-Jul-2013 [9102x2] | It's just a #define I use, mirroring the practice in C. Yes, it's an integer |
I'm defining many extra types in the bindings | |
Pekr 2-Jul-2013 [9104] | I hope after returning from ReCon, Doc is back on IO, we really need it to make more usefull stuff. Reading/writing files via some libraries is nice, but I want my read/lines :-) |
DocKimbel 2-Jul-2013 [9105x4] | Watching your video Arnold, great work! http://www.youtube.com/watch?v=qx-4K8F3VMM&list=PLr1rbtkaZDGDKtExuz8Q0nFDtDtUyyOHz |
Pekr: you might want to FB-it? ;-) | |
Ah, was expecting to see also the first compilation description...have to wait for the next episode! :-) | |
Maybe Pekr could do an Android Red app compilation + execution on the online emulator short video too? If it includes one of your nice models from the photo studio, that would be even better. ;-) | |
Pekr 2-Jul-2013 [9109] | No SW to record screen, so maybe later :-) |
Arnold 2-Jul-2013 [9110x2] | Pekr, I used Quicktime on OS X from 5.6, For windows there should be a pretty good freeware alternative |
Doc, thanks. Compilation description? Next step is to make a Red/System script and compile and test this. Then a Red script same storybook. Then calling R/S from Red example. | |
Arie 2-Jul-2013 [9112] | @Arnold nice ;-) Might be useful to add sequence numbers to video titles |
Endo 2-Jul-2013 [9113] | Nice work Arnold! |
Bo 2-Jul-2013 [9114x3] | I like your video, Arnold! |
Cross-posting on SO Chat. | |
Ah, second video already online: https://www.youtube.com/watch?v=7YPbEtG8mf0&list=PLr1rbtkaZDGDKtExuz8Q0nFDtDtUyyOHz | |
Kaj 2-Jul-2013 [9117] | Good initiative, Arnold |
Arnold 2-Jul-2013 [9118] | Thanks all. Numbering: I'll add a number at the end in square brackets like this [1] |
Kaj 2-Jul-2013 [9119] | Petr, you can implement read/lines right now on top of READ |
Arnold 2-Jul-2013 [9120] | Will the code be reusable in a pure Red solution if one would do that? To be able to do all kinds of possible things using Red bindings to C-libraries is great, beats not being able to do things by infinite factors. Still having the functionality coded in Red feels better. Open sourcing R3 has reminded everyone that it is made using C. HostileFork expresses the lack of development by the community as being caused by the difficulty and abstraction level of this C codebase. |
Kaj 2-Jul-2013 [9121x2] | There is no pure Red solution. When Doc will make an I/O framework, file I/O will still use a binding to the operating system underneath, which almost always means the standard C library |
In a framework with scheme handlers, code will have to be refactored, but pieces from the current code could still be used. They're already small pieces, anyway | |
Arnold 2-Jul-2013 [9123] | ok. The same solution was made for adding time or now you provided earlier. Somehow the timer has to be read using a standard C library. |
Kaj 2-Jul-2013 [9124] | Yes, if you don't want to write a lot of different code for different operating system kernels |
Arnold 2-Jul-2013 [9125] | One day I will understand and make the video ;-) |
Kaj 2-Jul-2013 [9126] | Koel :-) |
Arnold 2-Jul-2013 [9127] | Having to add all #include for many of these kind of common functionality (time random i/o etc) is less friendly than having these integrated. |
Kaj 2-Jul-2013 [9128x2] | Sure, that's why they're in separate repositories. When Red takes the pieces it needs, it won't be bothered by the full bindings, but they can still be used in Red/System programs |
In the meantime, if you want everything included, use the interpreter builds | |
Bo 2-Jul-2013 [9130] | 'make-c-string is my friend. My Red/System scripts are so much happier now that I'm not assigning c-strings to arbitrary locations in memory like I was doing with 'as-c-string. :-) |
Kaj 2-Jul-2013 [9131] | :-) Note that most of your string initialisations were unneeded. Several allocations are done by the functions you're calling |
Bo 2-Jul-2013 [9132x2] | How do I know when to initialize a string or not? I was just going to ask that question. Take this function from ANSI.reds for example: append-string: "strcat" [ "Append string." target [c-string!] source [c-string!] return: [c-string!] ] Can I just do this? file1: make-c-string 128 file2: make-c-string 128 file1: "to-process/" file2: "dir/" append-string file1 file2 append-string file1 "file.txt" |
I'm trying to track down an access violation. | |
Kaj 2-Jul-2013 [9134] | You're allocating both file1 and file2 double there. The two 128 byte strings immediately leak away when you assign the literals |
Bo 2-Jul-2013 [9135x2] | OK. So 'make-c-string isn't really needed? Isn't it like Rebol where if you don't do: copy "to-process/" that you will be linking to a static memory location with "to-process/" in it? |
linking = pointing | |
Kaj 2-Jul-2013 [9137] | Then when you append to file1, you're overwriting the string literal inside the executable, so you're destroying your program in memory |
Bo 2-Jul-2013 [9138] | So how would you write the above? |
older newer | first last |