These are chat archives for fourthbit/spheres

27th
Sep 2015
ovenpasta
@ovenpasta
Sep 27 2015 10:34

Also:

1> (load (spheres/net sack-server))
*** ERROR -- Ill-placed 'namespace'
(##namespace ("spheres/net/sack#io-primitives#"))

Sorry it was inside debugger :) It loads properly

Álvaro Castro-Castilla
@alvatar
Sep 27 2015 11:09
Yes the debugger thing is annoying :)
I wrote you back in Github. I'll fix the error loading the SDL2 bindings today. I think is best no to use R7RS library forms for bindings code since it is both just supporting Gambit and needs to be compiled anyway.
The code you did works just because if the file is already compiled, the "include" clauses won't be interpreted. Otherwise, you'd get an error mentioning that you cannot run c-define and other FFI functions in the interpreter.
The Sack server is a piece that needs some attention, but the architecture is very nice and is almost production-quality.
What needs is tests and some cleanup.
ovenpasta
@ovenpasta
Sep 27 2015 19:56
I found a bug in Sack, the procedure string->uri is not handling empty values
example:
> (string->uri "/foo?x=1&y=1")
#<uri #93 scheme: #f userinfo: #f host: #f port: #f path: "/foo" query: (("x" . "1") ("y" . "1")) fragment: #f>
> (string->uri "/foo?x=1&y=") 
Value: 0
Predicate: (lambda (len) (fx> len 0))
Reason: The input u8vector is not proper UTF-8.
*** ERROR IN #<procedure #94> -- Failed argument check in 'utf-u8vector->string
1>
the result is that the request hangs
ovenpasta
@ovenpasta
Sep 27 2015 20:16
I don't understand so which is the proper way to load the sdl2 module? I see that if it's not compiled I get the include error but anyway it needs compilation to use the ffi right?
ovenpasta
@ovenpasta
Sep 27 2015 20:38
Here I have another question consider the following code
(define SDL_RenderGetViewport (c-lambda (SDL_Renderer* SDL_Rect*) void "SDL_RenderGetViewport"))
how can I create and pass a SDL_Rect object to be filled in by the function?
ovenpasta
@ovenpasta
Sep 27 2015 20:48
also another nice feature maybe to be able to specify if pointers are const or not ;)
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 21:01
What do you mean by const pointers in Scheme?
The way to load and FFI code is to make sure you are compiling it, via (load (spheres/sdl2 sdl2) compile: #t))
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 21:06
Once the code is compiled you can freely load it.
But I need to review all this, it's been months since I touch this code unfortunately
I don't remember all detail ATM.
Ok, from what I can see in the code (I didn't remember all this), OpenGL, Cairo and SDL2 bindings need an update to account for latest changes in Spheres.
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 21:13
I think by the const thing you mean this: warning: assignment discards 'const'...
Well, that comes from Gambit, and if you want to silence it you need to add -w or the specific compiler flag.
(within the compilation flags passed to the library compilation)
Once you compile SDL2 or Cairo with "ssrun", you can load the "o1" files directly by hand, if you need them now until I can fix it.
ovenpasta
@ovenpasta
Sep 27 2015 21:22
By const I mean some way to specify in the signature that we are leading with const parameter. so that the user has some memo about the underlying c function. Also optional parameter names can be nice :) Maybe just create a normal scheme function that wraps the c-lambda can do it :)
I loaded the o1 file directly but how to access the functions? there is some namespace? in this case it is (spheres/sdl2 sdl2) but how in practice?
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 21:26
IIRC they have no namespace at the moment
ovenpasta
@ovenpasta
Sep 27 2015 21:26
> (load "/home/aldo/gambit/lib/spheres/spheres/sdl2/sdl2.o1")
"/home/aldo/gambit/lib/spheres/spheres/sdl2/sdl2.o1"
> (SDL_Init)
*** ERROR IN (console)@2.2 -- Unbound variable: SDL_Init
btw I can use the sld file anyway
I think most important is how to create the C structure and pass it as pointer to the function. It seems that there is no documentation regarding how to do it
ovenpasta
@ovenpasta
Sep 27 2015 21:31
something like this
(let ((rect (make-SDL_Rect 0 0 0 0)))
          (SDL_RenderGetViewport renderer rect)
          rect)
with the above defined as
(define SDL_RenderGetViewport (c-lambda (SDL_Renderer* SDL_Rect*) void "SDL_RenderGetViewport"))
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 21:37
Yes, feel free to create that documentation!
At the moment the spheres-doc project is stalled. The idea is to make it extract the comments as markdown or something simpler and generate a web.
But comments have to be created too :)
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 22:19
hey @ovenpasta , the error should be gone now with my latest changes
One thing to keep in mind: if you don't add an sld file, what you get is a flat namespace. But if you want to create proper modules, you need the sld file. However, the one you made was incomplete and didn't export any of the important procedures.
You can either keep no sld file, or add all the external API to exports.
For that reason, I removed the file temporarily, but you are free to provide a complete one!
Álvaro Castro-Castilla
@alvatar
Sep 27 2015 22:34
Finally, the sack bug needs and issue opened! At least we should record those things to start fixing them.