<abu[7]>
So the def in sys/socket.h is just an example
<abu[7]>
Siz may vary probably
<geri>
yeah
<abu[7]>
Bad C style
<geri>
okay i gotta work for a little bit, gonna be back later
<abu[7]>
Me too
<geri>
enjoy
<abu[7]>
☺
<geri>
i love how you can just do (de quote2 X X)
<geri>
and (de traditional_quote X (car X))
<geri>
how do i discard all output from a shell command?
<geri>
(in '(some command) NIL)?
<geri>
in particular im trying to make sure nohup wont be outputting to a file
<geri>
actually the thing we did with exec + fork may be more useful here than nohup
<geri>
yup, okay
<abu[7]>
Perhaps also (err "/dev/null" (in '(some command)))
<geri>
like 3 or 4 function names i usually use for functions in this script are occupied by pil builtins
<geri>
im sad
<abu[7]>
The use a namespace and (local)
rob_w has quit [Remote host closed the connection]
<beneroth>
hey abu[7] geri o/
<beneroth>
congrats :)
<abu[7]>
Ahoi beneroth!
<geri>
hi-hi
<geri>
yeah, it finally works 🥳
<geri>
i got query command working too, although its very bad
<geri>
so now just need to polish stuff up and ill have my script rewritten
<geri>
script is about using mpv as a music server using json ipc btw
<geri>
and problem ill need to figure out is that mpv actually sends events asyncronously, so ill have to figure out how to handle that
<geri>
(p.s. brb in ~20)
f8l has joined #picolisp
<geri>
silly question - how do i packJson a 0 to be 0 and not an empty object?
<geri>
actually nvm, i was using wrong pattern XD
fuxoft has joined #picolisp
<fuxoft>
Hello there.
<fuxoft>
Is there a function similar to (chop) that splits the string to single bytes instead to UTF characters?
<abu[7]>
Hi fuxoft! Not out of the box. I would use 'buf', 'struct' and 'byte'
f8l has quit [Ping timeout: 252 seconds]
<fuxoft>
Will look into those, thanks.
<abu[7]>
Let me try an example. It is similar to the above discussion.
<fuxoft>
And what about (char)? Can I read a single byte (not character) from the file?
<abu[7]>
Yes, thats easy
<abu[7]>
(rd 1)
<fuxoft>
Oooh, rd with a parameter, I missed that
<abu[7]>
(let S "a☺c" (buf B (inc (size S)) (struct B NIl (cons S (size S))) (for (P B (n0 (byte P)) (inc P)) (printsp (byte P)))))
<abu[7]>
Could be optimized a little
<fuxoft>
Without parameter, (pr) and (rd) use some specific packed format, is it described somewhere?
<fuxoft>
Oh that looks advanced, I will have to study that...
f8l has joined #picolisp
<abu[7]>
I think the format (PLIO) is not really documented
<fuxoft>
BTW is there a way to analyze (in pure PicoLisp) the low-level Cells in memory, e.g. seeing the actual pointer addresses and type bits...? It might help me understand the basic structures (symbols, lists) better.
<beneroth>
there is (adr)
<beneroth>
but probably not exactly what you are looking for
<beneroth>
(view) is also handy for lists and tree structures
<abu[7]>
I think (adr) can analyze anything
<fuxoft>
Yeah, (adr) looks like something I had in mind. Like "peek" on ZX Spectrum :)
<abu[7]>
eg, (struct (- (adr Sym) 8) T) gets the internal tail of a symbol
<fuxoft>
That emoji probably shouldn't be there...?
<abu[7]>
It is an example for a multi-byte char
<fuxoft>
And what's "Sym" here?
<fuxoft>
No, wait, there is definitely something wrong with that line, the parentheses are not matched
<beneroth>
fuxoft, it's an 8 followed by ), maybe your client shows a smiley instead
<fuxoft>
Yes, I am on web.libera.chat
<fuxoft>
When I tried that I got segfault...
<abu[7]>
Probably non-UTF
<abu[7]>
by copy/paste
<abu[7]>
Try some other chars
<fuxoft>
Instead of "Sym"? Sorry I am lost about what I should do.
<fuxoft>
I don't understand what's "Internal tail of a symbol" and what "Sym" represents.
<beneroth>
have you checked out @doc/Structures?
<abu[7]>
Ah, I talked about the chars
<fuxoft>
No, not at all.
<beneroth>
abu[7], 8) is displayed as a smiley picture for fuxoft, so your code is scrambled for him
<abu[7]>
Yes, understood it that way
<fuxoft>
I understand that it should be number 8 and closed parentheses but I have no idea what it should do and what should I put into "Sym" (if anything)
<fuxoft>
If I just enter that line in to REPL, it segfaults.
<beneroth>
Sym is the symbol you want to look at, extracting the tail from it in binary
<abu[7]>
Any symbol, perhaps with properties
<beneroth>
you first need to create it, else struct is reading nothing which causes the segfault
<abu[7]>
it was NIL probably which should be ok
<abu[7]>
You use pil21 ?
<abu[7]>
In pil64 it was different
<abu[7]>
T was not supported by 'struct' and 'adr' was different
<fuxoft>
Oh, the segfault was because i've put an integer in Sym before...
<abu[7]>
Ah, perfect :)
<fuxoft>
That's more food for my thought, I'll go back to studying, thanks :)
<abu[7]>
Good :)
<abu[7]>
(I avoid ☺)
fuxoft has quit [Quit: Client closed]
<geri>
avoid studyng? abu[7]
<abu[7]>
Avoid smileys
<geri>
:(
<abu[7]>
fuxofts client
<geri>
i wrote a very complex version of my script that uses sockets xd
<geri>
question
<geri>
how do i read bytes until newline?
<geri>
it seems that ascii chars and japanese characters occupy different amount of bytes
<geri>
so then everything is misaligned and i cry
<abu[7]>
Yes
<abu[7]>
size vs. length
<geri>
i read with (%@ "read" SOCKFD P 1)
<abu[7]>
but (rd 1) and (= "\n" B) works
<geri>
oh wait
<geri>
i should be able to read from file descriptor with picolisp's functions, no?
<abu[7]>
yes
<abu[7]>
"read" 1 is not so good
<geri>
need (line)
<abu[7]>
ok
<abu[7]>
(in SOCKFD ..
<geri>
hm
<geri>
(in SOCKFD (line T)) returns NIL
<geri>
reading with %@ returns chars as is needed
<abu[7]>
NIL means EOF
<geri>
its not eof though
<geri>
as in, file isnt closed
<abu[7]>
hmm
<abu[7]>
T
<abu[7]>
For TCP it works
<geri>
eh
<abu[7]>
Perhaps you need to set to unblocking
<geri>
how do i do that again?
<geri>
you can apparently set options like that onto fd's
<geri>
hm
<abu[7]>
I think @lib/net.l does it
<geri>
(%@ "nonBlocking" 'I Sd)
<geri>
okay..
<abu[7]>
Yeah
<geri>
returned a 2
<geri>
reading from fd with line still returns nil
<geri>
eh
<abu[7]>
I thought you need the opposite
<abu[7]>
blocking
<geri>
isnt it the default?
<abu[7]>
Right ...
<abu[7]>
probably
<geri>
i mean, i can probably get myself a buffer and put those 1 bytes into it until i find a newline and then use struct to extract chars properly or something
<abu[7]>
Read more
<abu[7]>
1 is not good
<beneroth>
can you not just need normal (till) and (from) and (line) with the fd you opened?
<abu[7]>
Then use byte
<abu[7]>
as above
<beneroth>
you should not mix (rd 'num) and text reading functions
<abu[7]>
T
<geri>
uh
<geri>
im using %@ "read""
<beneroth>
why
<geri>
for the same reason why i use %@ write
<geri>
xd
<geri>
(ie probably cause im stupid)
<geri>
let me try to send a command to fd using pico functions
<beneroth>
there might be a good reason for it. but why not use (rd 'num) and (wr 'num) if you need binary io, or (prinl)/(prin)/(char)/(till)/(line) if you do text io?
<beneroth>
yeah
<geri>
cause i know 0 of these?
<beneroth>
ah
<beneroth>
thats a good reason
<geri>
okay i have a socket file descriptor
<geri>
how do i send a string to it
<beneroth>
I thought you know them and considered some reason not to use them :D
<beneroth>
(prinl)
<geri>
(out SOCKFD (prinl "cycle pause"))
<beneroth>
or just (prin)
<geri>
doesnt work
<geri>
says bad file descryptor
<geri>
descriptor
<beneroth>
hmmm
<geri>
i can %@ write to it fine
<abu[7]>
strange
<geri>
cffi do be strage :D
<geri>
so this works: (let S "cycle pause\n" (%@ "write" 'I SOCKFD S (length S)))
<geri>
this doesnt: (out SOCKFD (prinl "cycle pause\n"))
<abu[7]>
Something special with unix socks
<abu[7]>
Ah
<beneroth>
or something that is checked when using (out) ?
<abu[7]>
Not ah
<abu[7]>
I thought you need (flush)
<beneroth>
good point
<abu[7]>
but 'out' takes care of it
<abu[7]>
(flushes in the end)
<geri>
3 -- Bad FD
<geri>
let me try to grep through the code base...