chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Question about embedding Chicken scheme


From: Kristian Lein-Mathisen
Subject: Re: [Chicken-users] Question about embedding Chicken scheme
Date: Thu, 31 Jan 2013 00:04:27 +0100


I see Julian, so when you said you were looking for an "embedded language for doing quests" that's exactly what you meant... :)

I'm curious how you end up splitting your data structures. Perhaps it's all in C/C++ and then you access then from Scheme? There's an example of you might do that, if you haven't found out already:
http://wiki.call-cc.org/Wrapping%20simple%20c%20structs

You can also use chicken-bind to familiarize yourself with foreign-lambda and friends. Chicken-bind has almost a complete C/C++ parser and can produce foreign-lambdas:

$ echo "struct player { int level, health; }" | chicken-bind - -o -

;;; GENERATED BY CHICKEN-BIND FROM -

(begin
  (define player-level
    (foreign-lambda*
      integer
      (((c-pointer (struct "player")) s))
      "return(s->level);"))
  (define player-health
    (foreign-lambda*
      integer
      (((c-pointer (struct "player")) s))
      "return(s->health);"))
  (define make-player
    (foreign-lambda*
      (c-pointer (struct "player"))
      ((integer level) (integer health))
      "struct player *tmp_ =  (struct player *)C_malloc(sizeof(struct player));\ntmp_->level = level;\ntmp_->health = health;\nreturn(tmp_);;\n")))

;;; END OF FILE

If you don't have it already, you can do `chicken-install bind` and play around. Note that `make-player` above leaks memory.

Best of luck!
K.


On Thu, Jan 24, 2013 at 1:25 AM, Julian Day <address@hidden> wrote:
On 23/01/2013 6:09 PM, Kristian Lein-Mathisen wrote:

Are you planning on using any established game-engines or libraries?
What will probably become very interesting is where your C++-code ends
and where your Scheme begins.

Hi Kristian,

The game is currently pure C and C++.  As for libraries, I currently use xerces (XML), curses (UI), Google Test, and boost/stl.  The game itself is currently in a playable state - the player can win or lose, there's a generated world to explore, etc., though it's currently pretty bare.

My plan is to start with reasonably small scope, and use Scheme for the quest logic.  I'd like to have a number of optional side quests beyond the basic roguelike "dive to the bottom of the dungeon".  I could do this in C++, but I see an opportunity to work in my favourite programming language, so I'm going to take it. :)

So I have a crazy idea, how about writing all of it in Scheme? So
instead of exposing a function to add a message to the UI, you can
expose functions to draw the UI,  and do your game in Scheme. Then as
you move along and things settle, you can port the slow/critical parts
to faster C-code if you need to. Just a thought. There are several eggs
<http://wiki.call-cc.org/chicken-projects/egg-index-4.html#graphics> for

graphics available that might suit your drawing needs, like cairo or opengl.

Much too late for that, I'm afraid!  The game itself is currently just under 2 MB of code, resource strings, and configuration details.  I'm quite happy with its current state.  I'd love to try Scheme as the main language for a game, but this project's much too far in for that.

Julian



reply via email to

[Prev in Thread] Current Thread [Next in Thread]