Author Topic: Programming Fun  (Read 5092 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
Re: Programming Fun
« Reply #15 on: March 05, 2013, 03:34:03 AM »
Charles..
I don't use ENUM very much but i found that old way is simple to use
so do you will make this optional ?

Charles Pegge

  • Guest
Re: Programming Fun
« Reply #16 on: March 05, 2013, 04:13:50 AM »
Hi Aurel,

you can define enumerations in the same way as before. The only difference is that all the enumeration members become equates, and you wont need dotted names to access them directly.

SDL example:

Code: [Select]
typedef enum {
  SDL_GL_RED_SIZE,
  SDL_GL_GREEN_SIZE,
  SDL_GL_BLUE_SIZE,
  SDL_GL_ALPHA_SIZE,
  SDL_GL_BUFFER_SIZE,
  SDL_GL_DOUBLEBUFFER,
  SDL_GL_DEPTH_SIZE,
  SDL_GL_STENCIL_SIZE,
  SDL_GL_ACCUM_RED_SIZE,
  SDL_GL_ACCUM_GREEN_SIZE,
  SDL_GL_ACCUM_BLUE_SIZE,
  SDL_GL_ACCUM_ALPHA_SIZE,
  SDL_GL_STEREO,
  SDL_GL_MULTISAMPLEBUFFERS,
  SDL_GL_MULTISAMPLESAMPLES,
  SDL_GL_ACCELERATED_VISUAL,
  SDL_GL_SWAP_CONTROL
} SDL_GLattr

print SDL_GL_BLUE_SIZE 'result: 2



Charles


Peter

  • Guest
Re: Programming Fun
« Reply #17 on: March 05, 2013, 05:23:50 AM »
But  what is when the numeration isn't  1-2-3-4,  rather  0-0-1-8-9-20-21 !

Peter

  • Guest
Re: Programming Fun
« Reply #18 on: March 05, 2013, 05:41:26 AM »
Hi John,

Is this vala source code from another star ?
I didn't know that Aliens have pseudo C.

This is a bit better readable.
Code: [Select]
include "sdl.inc"

LoadWinIcon "img/hase.bmp"
Window 640,480,1
SetCaption "Random Circles"

Type CIRCLE
  sys x
  sys y
  sys c
  sys a
End Type

CIRCLE cir[500]
sys i

for i=1 to 500
    cir[i].x = Rnd(0,640)
    cir[i].y = Rnd(0,480)
    cir[i].a = Rnd(10,100)
    cir[i].c = RGBA(Rnd(64,255),Rnd(64,255),Rnd(64,255),Rnd(64,255))
next

while Key(27)=0
  Cls RGB(255,255,255)
  for i=1 to 500
      filledCircleColor @screen,cir[i].x,cir[i].y,cir[i].a,cir[i].c
  next  
  Sync()
wend

Quit()
« Last Edit: March 05, 2013, 10:55:17 PM by peter »

Charles Pegge

  • Guest
Re: Programming Fun
« Reply #19 on: March 05, 2013, 06:05:06 AM »
Aurel,
Specifying enumeration values:

Code: [Select]
typedef enum {
  SDLK_UNKNOWN     = 0,
  SDLK_FIRST     = 0,
  SDLK_BACKSPACE    = 8,
  SDLK_TAB     = 9,
  SDLK_CLEAR     = 12,
  SDLK_RETURN     = 13,
  SDLK_PAUSE     = 19,
  SDLK_ESCAPE     = 27,
  SDLK_SPACE     = 32,
  SDLK_EXCLAIM     = 33,
...

Charles Pegge

  • Guest
Re: Programming Fun
« Reply #20 on: March 05, 2013, 06:10:44 AM »

The new simplified enumeration system compatible with C enums:

Also fixes nasty little bug affecting inner functions

X

Aurel

  • Guest
Re: Programming Fun
« Reply #21 on: March 05, 2013, 06:37:21 AM »
Thanks Charles...
I don't ask about random or not continued enumeration then Peter ask
however ,so if we need not-continued way we must use enum-assign way which is ok for me.. :)

Hmm...Vala looks like ObjectOrientedBisexual child of C... ;D
And Genie is a little bit better OOB child of Vala :D

JRS

  • Guest
Re: Programming Fun
« Reply #22 on: March 05, 2013, 08:20:45 AM »
Quote
Hmm...Vala looks like ObjectOrientedBisexual child of C.

The Vala/Genie language is based on the GObject framework.

Check out the GObject Reference Manual.

@Peter: Check out the Vala SDL API definition file I attached. I find it helpful  as a reference to the SDL library in general. SDL.h only, see other {SDL}.vapi files for other aspects of the library.

Quote
C APIs are defined by a set of functions and global variables which are usually exported from a binary. C functions have an arbitrary number of arguments and one return value. Each function is thus uniquely identified by the function name and the set of C types which describe the function arguments and return value. The global variables exported by the API are similarly identified by their name and their type.

A C API is thus merely defined by a set of names to which a set of types are associated. If you know the function calling convention and the mapping of the C types to the machine types used by the platform you are on, you can resolve the name of each function to find where the code associated to this function is located in memory, and then construct a valid argument list for the function. Finally, all you have to do is trigger a call to the target C function with the argument list.

The concept DLLC is based on.

ScriptBasic is in many ways an early adoption of the GObject concept. (released over 10 years ago and why it still runs today using one source tree for all platforms)

X
« Last Edit: March 05, 2013, 11:11:24 AM by JRS »