Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Go binding for SFML  (Read 13636 times)

0 Members and 2 Guests are viewing this topic.

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Go binding for SFML
« on: July 12, 2012, 07:26:04 am »
Some weeks go I fell in love of Go (golang.org), and because I really like SFML I would like to use it with Go.
There is no binding yet, so instead of waiting for someone doing, I should do it myself.

Right now, the only way to bind C++ to Go is using SWIG. I have read an old post speaking about SWIG. Are PySFML and rbSFML using SWIG ?
Is there some work used for the previous binding I can use ?

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Go binding for SFML
« Reply #1 on: July 12, 2012, 10:36:10 am »
as i remember, GO can link with C libraries, i think you can make binding on top of C libs
check this : http://golang.org/doc/articles/c_go_cgo.html

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #2 on: July 12, 2012, 11:33:10 am »
That's true, it's another possibilities, doing the Go binding from the C binding.
But it's a bit weird to do a binding from another binding, isn't? Seems not very clean… (maybe it's still the best idea)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Go binding for SFML
« Reply #3 on: July 12, 2012, 12:04:22 pm »
Quote
But it's a bit weird to do a binding from another binding, isn't? Seems not very clean…
C has a standard ABI (binary interface), C++ doesn't. Therefore is it common that bindings require an intermediate C binding; not all languages support being linked to C++ directly.

In fact SWIG will probably generate this intermediate C binding automatically for languages that can't link to C++.
Laurent Gomila - SFML developer

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #4 on: July 12, 2012, 09:16:47 pm »
In fact SWIG will probably generate this intermediate C binding automatically for languages that can't link to C++.

Yes that's true. But SWIG will detect a class and bind it to go using interface and not giving the object struct pointer as first arguments.
Anyway, I'm sure the best is doing it by hand. I will try.

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #5 on: July 15, 2012, 12:24:41 pm »
I begin to bind some function, just the Window functions for testing.
But I have an error Cannot create a window from a worker thread. (OS X limitation). I sure is because of the thread go use for his runtime. But that mean on Mac OS X the binding can be hard to do because I can't force Go to execute my app in the main thread.

daemon

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Go binding for SFML
« Reply #6 on: July 18, 2012, 08:36:52 pm »
I wrote Go bindings some time ago in order to get familiar with Go. Maybe you'd like to check out my repository.
Binding: https://bitbucket.org/krepa098/gosfml2
Samples: https://bitbucket.org/krepa098/gosfml2-samples
I'm not sure whether I did it right as I'm quite new to the Go language, but at least it seems to work.  :)

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #7 on: July 19, 2012, 08:38:24 pm »
That's great! I'm also new on Go universe, so I don't know either if my binding would follow the right convention. I check out your work, is really great. Did you write it by hand or is it generated?
You follow the same convention as me, so I like it!

daemon

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Go binding for SFML
« Reply #8 on: July 20, 2012, 02:38:18 pm »
Yes it's all handwritten (with a lot of copy-pasting involved). Do you actually cast Go-structs to C, like in toCPtr()? I don't think it's safe because the compiler could decide to add padding.  :-\ Any ideas?

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #9 on: July 20, 2012, 08:36:58 pm »
No… I guess it's possible but I didn't find any document for Go to C. But where do you need to cast Go struct to C ?

daemon

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Go binding for SFML
« Reply #10 on: July 22, 2012, 05:13:03 pm »
I was actually referring to this file (line 44). I know that I can work around it but I'm not sure if I really have to. Anyway, the bindings should be almost complete by now.

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Go binding for SFML
« Reply #11 on: July 22, 2012, 07:45:51 pm »
I don't find a way to do that. But you can convert it to a C.Rectf, then copy the four attribute.

gyscos

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Re: Go binding for SFML
« Reply #12 on: November 27, 2012, 09:28:33 am »
It really looks great, and I'm eager to try it - but how do you build the library ?

I "go get"ed it, but when I try go build I get these errors :
1: error: 'sfJoystickConnectEvent' undeclared (first use in this function)
... and 8 other similar errors, with other Event types.

I have the last SFML sources (from 2012-11-24) ; is this a problem ? Do I need to put them somewhere specific ?

EDIT : just noticed I also might need csfml. I have version 1.99 from 2012-05-04. Is it too old ?
EDIT2 : Ow, grabbed csfml from git, and it works ! :D Quite impressive...
« Last Edit: November 27, 2012, 09:45:17 am by gyscos »

daemon

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Go binding for SFML
« Reply #13 on: November 28, 2012, 06:07:07 pm »
I'm trying to keep up with SFML git. That's why you need the latest version of SFML and CSFML. I hope you'll enjoy it. Feedback is welcome.  :)

gyscos

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Re: Go binding for SFML
« Reply #14 on: November 28, 2012, 10:07:58 pm »
The lack of any good gui or graphic library for go really turned me down, so finding this was quite exciting. As soon as I finish the mandatory tetris clone, I'll try some fun thing and let you know how gosfml goes :)