Académique Documents
Professionnel Documents
Culture Documents
")
nOption = GetString()
switch nOption {
case 1
print("Enter your name : ")
name = getstring()
print("Hello #{name}\n")
case 2
print("Sample : using switch statement\n")
case 3
Bye
else
print("bad option...\n")
}
Note: All of these styles are provided automatically by the compiler at the same time, Its better to select one style for
the same project (you can create your style as a mix from these styles) for example you can use Put/Get and Braces.
Changed:
get() function : changed to sysget()
sort() function : can now work on list of objects
find() function : can now work on list of objects
Added:
clockspersecond()
CurrentDir()
ExeFileName()
ChDir()
ExeFolder()
varptr()
space()
nullpointer()
object2pointer()
pointer2object()
Check the next chapters
System Functions
Object Oriented Programming (OOP)
Low Level Functions
Ring 1.1 comes with a library called StdLib, its written in Ring by the help of Ring Team
The library provide a useful group of new functions and classes
Example:
Load "stdlib.ring"
Puts("Test Times()")
Times ( 3 , func { see "Hello, World!" + nl } )
Example:
Load "stdlib.ring"
Puts("Test Map()")
See Map( 1:10, func x { return x*x } )
Example:
Load "stdlib.ring"
Puts("Test Filter()")
See Filter( 1:10 , func x { if x <= 5 return true else return false ok } )
Example:
Load "stdlib.ring"
Example:
Load "stdlib.ring"
Example:
Load "stdlib.ring"
Example:
Load "stdlib.ring"
Example:
Load "stdlib.ring"
Example:
Load "stdlib.ring"
}
}
oTree.children[2].children[3].children[3].set("2.3.3")
}
see copy("*",60) + nl
oTree.print()
9.7 RingLibSDL
Ring 1.0 provided RingAllegro to be able to create games using the Allegro game programming library
Now Ring 1.1 provide RingLibSDL also so we can have the choice between Allegro or LibSDL
Example:
Load "libsdl.ring"
SDL_Init(SDL_INIT_EVERYTHING)
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN)
SDL_Delay(2000)
SDL_DestroyWindow(win)
SDL_Quit()
In practice we would create a game engine in a language like C/C++ to get the best performance then provide Ring
classes to use the engine.
But many 2D Games are simple and creating a game engine in Ring will be fast enough in many cases
Also this would be a good demo project to learn about the language concepts where we build things using Object Ori-
ented Programming (OOP) then access the power that we have using declarative programming using nested structures
or using natural programming.
In this project we selected the first way (declarative programming using nested structures)
Example:
Load "gameengine.ring" # Give Control to the Game Engine
9.7. RingLibSDL 98
Ring Documentation, Release 1.5
file = "fonts/pirulen.ttf"
text = "game development using ring is very fun!"
color = rgb(0,0,0) # Color = black
}
text {
x = 10 y=150
# Animation Part ======================================
animate = true # Use Animation
direction = GE_DIRECTION_INCVERTICAL # Increase y
point = 400 # Continue until y=400
nStep = 3 # Each time y+= 3
#======================================================
size = 20
file = "fonts/pirulen.ttf"
text = "welcome to the real world!"
color = rgb(0,0,255) # Color = Blue
}
Sound { # Play Sound
file = "sound/music1.wav" # Sound File Name
}
} # Start the Events Loop
9.9 RingSQLite
Ring 1.0 provided support for ODBC to use any database and provided native support for MySQL.
Now Ring 1.1 provide native support for SQLite database too.
Example:
oSQLite = sqlite_init()
sqlite_open(oSQLite,"mytest.db")
sqlite_execute(oSQLite,sql)
sqlite_execute(oSQLite,sql)
9.9. RingSQLite 99
Ring Documentation, Release 1.5
for x in aResult
for t in x
see t[2] + nl
next
next
see copy("*",50) + nl
for x in aResult
see x["name"] + nl
next
sqlite_close(oSQLite)
We are using the code generator (written in Ring) every day to add new libraries to Ring.
The generator is used to create RingQt and RingAllegro
Also in Ring 1.1 its used to create RingLibSDL.
more features are added like
Set/Get structure members (numbers & pointers)
Using constants
Better Generated Code
See the Code Generator chapter.
We can use Self.Attribute in the Class Region (after the class name and before any methods) to define new attributes.
class Person
name # Define name as attribute if it's not a global variable
address
phone
class person2
self.name # Must Define the attribute
self.address
self.phone
We can use nested braces {} while we are inside methods to access another objects, In this case the current object
scope will be changed while we are inside the brace and Self will point to the object that we access using braces {}. In
this case we can use This.Attribute and This.Method() to access the object that will be created from the current class.
Check the Object Oriented Programming chapter for more information.
Also Check the Weight History Application in GUI Development using RingQt chapter.
Ring 1.1 documentation (800 pages) is better than Ring 1.0 documentation (340 pages)
Many chapters are added for providing better information about the language like
Language Reference
Scope Rules
FAQ
And more!
TEN
The Ring programming language is a free open source product (MIT License).
You can build Ring using CMake or using Scripts (Batch Files or Shell Scripts).
The next steps explains building using scripts.
Build RingODBC
cd ../extensions/ringodbc
buildvc.bat
Build RingMySQL
cd ../extensions/ringmysql
buildvc.bat
Build RingSQLite
cd ../extensions/ringsqlite
buildvc.bat
Build RingOpenSSL
cd ../extensions/ringopenssl
buildvc.bat
Build RingInternet
cd ../extensions/ringinternet
buildvc.bat
102
Ring Documentation, Release 1.5
cd ../extensions/ringallegro
gencode.bat
buildvc.bat
Install Libraries
cd ring/src
./installdep.sh
Build RingODBC
cd ../extensions/ringodbc
./buildgcc.sh
Build RingMySQL
cd ../extensions/ringmysql
./buildgcc.sh
Build RingSQLite
cd ../extensions/ringsqlite
./buildgcc.sh
Build RingOpenSSL
cd ../extensions/ringopenssl
./buildgcc.sh
Build RingInternet
cd ../extensions/ringinternet
./buildgcc.sh