Ring Documentation, Release 1.3
}
}
oTree.children[2].children[3].children[3].set("2.3.3")
}
see copy("*",60) + nl
oTree.print()
Check the next chapters:
• StdLib Functions
• StdLib Classes
6.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()
See the RingLibSDL Chapter.
6.8 Demo Project - Game Engine for 2D Games
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
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
text {
x = 10 y=50
animate = false
size = 20
6.7. RingLibSDL 48
Ring Documentation, Release 1.3
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
See the “Demo Project - Game Engine for 2D Games” chapter.
6.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")
sql = "CREATE TABLE COMPANY(" +
"ID INT PRIMARY KEY NOT NULL," +
"NAME TEXT NOT NULL," +
"AGE INT NOT NULL," +
"ADDRESS CHAR(50)," +
"SALARY REAL );"
sqlite_execute(oSQLite,sql)
sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " +
"VALUES (1, 'Mahmoud', 29, 'Jeddah', 20000.00 ); " +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " +
"VALUES (2, 'Ahmed', 27, 'Jeddah', 15000.00 ); " +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" +
"VALUES (3, 'Mohammed', 31, 'Egypt', 20000.00 );" +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" +
"VALUES (4, 'Ibrahim', 24, 'Egypt ', 65000.00 );"
sqlite_execute(oSQLite,sql)
aResult = sqlite_execute(oSQLite,"select * from COMPANY")
6.9. RingSQLite 49
Ring Documentation, Release 1.3
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)
6.10 Better Code Generator for Extensions
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 it’s 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.
6.11 Using Self.Attribute in the Class Region to define new attributes
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
6.12 Using This.Attribute in nested Braces inside the Class Methods
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.
6.10. Better Code Generator for Extensions 50
Ring Documentation, Release 1.3
6.13 Better Documentation
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!
6.13. Better Documentation 51
CHAPTER
SEVEN
BUILDING FROM SOURCE CODE
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.
7.1 Building using Microsoft Windows
Get the source code
git clone http://github.com/ring-lang/ring.git
Build Ring (Compiler/VM)
cd ring/src
buildvccomplete.bat
buildvccompletew.bat
Generate RingAllegro Source Code and Build
cd ../extensions/ringallegro
gencode.bat
buildvc.bat
Generate RingLibCurl Source Code and Build
cd ../extensions/ringcurl
gencode.bat
buildvc.bat
Generate RingZip Source Code and Build
cd ../extensions/ringzip
gencode.bat
buildvc.bat
Install Qt 5.5 : https://download.qt.io/archive/qt/5.5/5.5.1/
Generate RingQt Source Code and Build
cd ../ringqt
gencode.bat
buildmingw32.bat
To be able to call ring from any folder
52
Ring Documentation, Release 1.3
cd ../../bin
install.bat
Add Ring/bin to System path
Hit "windows key".
Type "Edit the System environment variables"
Select "Advanced" tab.
Click on "Enviroment Variables..."
Double click on "Path"
Add at the end the new path separated by semicolon.
;C:RingBin
Run Ring Notepad
cd applications/rnote
ring rnote.ring
7.2 Building using Ubuntu Linux
Get the source code
git clone http://github.com/ring-lang/ring.git
Install Libraries
cd ring/src
./installdep.sh
Build Ring (Compiler/VM)
sudo ./buildgcccomplete.sh
Generate RingAllegro Source Code and Build
cd ../extensions/ringallegro
./gencode.sh
./buildgcc.sh
Generate RingLibCurl Source Code and Build
cd ../extensions/ringcurl
./gencode.sh
./buildgcc.sh
Generate RingZip Source Code and Build
cd ../extensions/ringzip
./gencode.sh
./buildgcc.sh
Generate RingQt Source Code and Build
cd ../ringqt
./gencode.sh
./buildgcc.sh
To be able to call ring from any folder
7.2. Building using Ubuntu Linux 53
Ring Documentation, Release 1.3
cd ../../bin
sudo ./install.sh
Run Ring Notepad
cd applications/rnote
sudo ring rnote.ring
7.3 Building using MacOS X
Get the source code
git clone http://github.com/ring-lang/ring.git
Install homebrew (follow the directions on homebrew’s homepage). Install Libraries
brew install unixodbc mysql-connector-c allegro openssl homebrew/versions/qt55
brew link --force qt55
Build Ring (Compiler/VM)
cd ring/src
./buildclangcomplete.sh
Generate RingAllegro Source Code and Build
cd ../extensions/ringallegro
./gencode.sh
./buildclang.sh
Generate RingLibCurl Source Code and Build
cd ../extensions/ringcurl
./gencode.sh
./buildclang.sh
Generate RingZip Source Code and Build
cd ../extensions/ringzip
./gencode.sh
./buildclang.sh
Generate RingQt Source Code and Build
cd ../ringqt
./gencode.sh
./buildclang.sh
To be able to call ring from any folder
cd ../../bin
sudo ./install.sh
Run Ring Notepad
cd applications/rnote
sudo ring rnote.ring
7.3. Building using MacOS X 54
Ring Documentation, Release 1.3
7.4 Building using CMake
Install libraries (MySQL Client, OpenSSL, LibCurl, Allegro 5 and Qt 5.5)
cmake .
make
7.4. Building using CMake 55
CHAPTER
EIGHT
HOW TO CONTRIBUTE?
Ring is a free-open source project, Everyone is welcome to contribute to Ring.
Project Home : https://github.com/ring-lang/ring
You can help in many parts in the project
• Documentation
• Testing
• Samples
• Applications
• Editors Support
• Libraries in Ring
• Extensions in C/C++
• Compiler and Virtual Machine (VM)
• Ideas and suggestions
8.1 Special thanks to contributors
Throughout the creation of this project, Ring relied heavily on contributions from experts along with college students.
Their input was invaluable, and we want to take a moment to thank them and recognize them for all of their hard work.
Ring Team: http://ring-lang.sf.net/team.html
8.2 Documentation
You can modify anything in the documentation, by updating the text files (*.txt) in this folder : https://github.com/ring-
lang/ring/tree/master/docs/source
The documentation is created using Sphinx : http://www.sphinx-doc.org/en/stable/
8.3 Testing
You can write new tests in this folder
https://github.com/ring-lang/ring/tree/master/tests/scripts
56
Ring Documentation, Release 1.3
8.4 Samples
You can add new samples to this folder
https://github.com/ring-lang/ring/tree/master/samples/other
8.5 Applications
You can add new applications to this folder
https://github.com/ring-lang/ring/tree/master/applications
8.6 Editors Support
You can help in supporting Ring in different code editors
Check the next folder
https://github.com/ring-lang/ring/tree/master/editor
8.7 Libraries in Ring
You can update and add libraries to this folder
https://github.com/ring-lang/ring/tree/master/ringlibs
8.8 Extensions in C/C++
You can add and update extensions in this folder
https://github.com/ring-lang/ring/tree/master/extensions
8.9 Compiler and Virtual Machine (VM)
• Source Code (C Language) : https://github.com/ring-lang/ring/tree/master/src
• Visual Source (PWCT) : https://github.com/ring-lang/ring/tree/master/visualsrc
8.10 Ideas and suggestions
You can share your ideas, suggestions and questions in this group
https://groups.google.com/forum/#!forum/ring-lang
8.4. Samples 57

The Ring programming language version 1.3 book - Part 8 of 88

  • 1.
    Ring Documentation, Release1.3 } } oTree.children[2].children[3].children[3].set("2.3.3") } see copy("*",60) + nl oTree.print() Check the next chapters: • StdLib Functions • StdLib Classes 6.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() See the RingLibSDL Chapter. 6.8 Demo Project - Game Engine for 2D Games 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 func main # Called by the Game Engine oGame = New Game # Create the Game Object { title = "My First Game" text { x = 10 y=50 animate = false size = 20 6.7. RingLibSDL 48
  • 2.
    Ring Documentation, Release1.3 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 See the “Demo Project - Game Engine for 2D Games” chapter. 6.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") sql = "CREATE TABLE COMPANY(" + "ID INT PRIMARY KEY NOT NULL," + "NAME TEXT NOT NULL," + "AGE INT NOT NULL," + "ADDRESS CHAR(50)," + "SALARY REAL );" sqlite_execute(oSQLite,sql) sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " + "VALUES (1, 'Mahmoud', 29, 'Jeddah', 20000.00 ); " + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " + "VALUES (2, 'Ahmed', 27, 'Jeddah', 15000.00 ); " + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" + "VALUES (3, 'Mohammed', 31, 'Egypt', 20000.00 );" + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" + "VALUES (4, 'Ibrahim', 24, 'Egypt ', 65000.00 );" sqlite_execute(oSQLite,sql) aResult = sqlite_execute(oSQLite,"select * from COMPANY") 6.9. RingSQLite 49
  • 3.
    Ring Documentation, Release1.3 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) 6.10 Better Code Generator for Extensions 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 it’s 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. 6.11 Using Self.Attribute in the Class Region to define new attributes 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 6.12 Using This.Attribute in nested Braces inside the Class Methods 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. 6.10. Better Code Generator for Extensions 50
  • 4.
    Ring Documentation, Release1.3 6.13 Better Documentation 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! 6.13. Better Documentation 51
  • 5.
    CHAPTER SEVEN BUILDING FROM SOURCECODE 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. 7.1 Building using Microsoft Windows Get the source code git clone http://github.com/ring-lang/ring.git Build Ring (Compiler/VM) cd ring/src buildvccomplete.bat buildvccompletew.bat Generate RingAllegro Source Code and Build cd ../extensions/ringallegro gencode.bat buildvc.bat Generate RingLibCurl Source Code and Build cd ../extensions/ringcurl gencode.bat buildvc.bat Generate RingZip Source Code and Build cd ../extensions/ringzip gencode.bat buildvc.bat Install Qt 5.5 : https://download.qt.io/archive/qt/5.5/5.5.1/ Generate RingQt Source Code and Build cd ../ringqt gencode.bat buildmingw32.bat To be able to call ring from any folder 52
  • 6.
    Ring Documentation, Release1.3 cd ../../bin install.bat Add Ring/bin to System path Hit "windows key". Type "Edit the System environment variables" Select "Advanced" tab. Click on "Enviroment Variables..." Double click on "Path" Add at the end the new path separated by semicolon. ;C:RingBin Run Ring Notepad cd applications/rnote ring rnote.ring 7.2 Building using Ubuntu Linux Get the source code git clone http://github.com/ring-lang/ring.git Install Libraries cd ring/src ./installdep.sh Build Ring (Compiler/VM) sudo ./buildgcccomplete.sh Generate RingAllegro Source Code and Build cd ../extensions/ringallegro ./gencode.sh ./buildgcc.sh Generate RingLibCurl Source Code and Build cd ../extensions/ringcurl ./gencode.sh ./buildgcc.sh Generate RingZip Source Code and Build cd ../extensions/ringzip ./gencode.sh ./buildgcc.sh Generate RingQt Source Code and Build cd ../ringqt ./gencode.sh ./buildgcc.sh To be able to call ring from any folder 7.2. Building using Ubuntu Linux 53
  • 7.
    Ring Documentation, Release1.3 cd ../../bin sudo ./install.sh Run Ring Notepad cd applications/rnote sudo ring rnote.ring 7.3 Building using MacOS X Get the source code git clone http://github.com/ring-lang/ring.git Install homebrew (follow the directions on homebrew’s homepage). Install Libraries brew install unixodbc mysql-connector-c allegro openssl homebrew/versions/qt55 brew link --force qt55 Build Ring (Compiler/VM) cd ring/src ./buildclangcomplete.sh Generate RingAllegro Source Code and Build cd ../extensions/ringallegro ./gencode.sh ./buildclang.sh Generate RingLibCurl Source Code and Build cd ../extensions/ringcurl ./gencode.sh ./buildclang.sh Generate RingZip Source Code and Build cd ../extensions/ringzip ./gencode.sh ./buildclang.sh Generate RingQt Source Code and Build cd ../ringqt ./gencode.sh ./buildclang.sh To be able to call ring from any folder cd ../../bin sudo ./install.sh Run Ring Notepad cd applications/rnote sudo ring rnote.ring 7.3. Building using MacOS X 54
  • 8.
    Ring Documentation, Release1.3 7.4 Building using CMake Install libraries (MySQL Client, OpenSSL, LibCurl, Allegro 5 and Qt 5.5) cmake . make 7.4. Building using CMake 55
  • 9.
    CHAPTER EIGHT HOW TO CONTRIBUTE? Ringis a free-open source project, Everyone is welcome to contribute to Ring. Project Home : https://github.com/ring-lang/ring You can help in many parts in the project • Documentation • Testing • Samples • Applications • Editors Support • Libraries in Ring • Extensions in C/C++ • Compiler and Virtual Machine (VM) • Ideas and suggestions 8.1 Special thanks to contributors Throughout the creation of this project, Ring relied heavily on contributions from experts along with college students. Their input was invaluable, and we want to take a moment to thank them and recognize them for all of their hard work. Ring Team: http://ring-lang.sf.net/team.html 8.2 Documentation You can modify anything in the documentation, by updating the text files (*.txt) in this folder : https://github.com/ring- lang/ring/tree/master/docs/source The documentation is created using Sphinx : http://www.sphinx-doc.org/en/stable/ 8.3 Testing You can write new tests in this folder https://github.com/ring-lang/ring/tree/master/tests/scripts 56
  • 10.
    Ring Documentation, Release1.3 8.4 Samples You can add new samples to this folder https://github.com/ring-lang/ring/tree/master/samples/other 8.5 Applications You can add new applications to this folder https://github.com/ring-lang/ring/tree/master/applications 8.6 Editors Support You can help in supporting Ring in different code editors Check the next folder https://github.com/ring-lang/ring/tree/master/editor 8.7 Libraries in Ring You can update and add libraries to this folder https://github.com/ring-lang/ring/tree/master/ringlibs 8.8 Extensions in C/C++ You can add and update extensions in this folder https://github.com/ring-lang/ring/tree/master/extensions 8.9 Compiler and Virtual Machine (VM) • Source Code (C Language) : https://github.com/ring-lang/ring/tree/master/src • Visual Source (PWCT) : https://github.com/ring-lang/ring/tree/master/visualsrc 8.10 Ideas and suggestions You can share your ideas, suggestions and questions in this group https://groups.google.com/forum/#!forum/ring-lang 8.4. Samples 57