SlideShare a Scribd company logo
Ring Documentation, Release 1.6
67.5 Building standalone console application
Using the “-static” option we can build executable console application
So we don’t have to use ring.dll, ring.so or ring.dylib
This avoid only the need to Ring dynamic link library
If you are using another libraries, You will need to include it with your application.
ring2exe test.ring -static
67.6 Distributing RingAllegro Applications
We have test2.ring contains the next code
# Just a simple program to test Ring2EXE Tool!
# Using RingAllegro
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"
}
To build the executable file and prepare for distributing the Game
We use “-dist” option and “-allruntime” to include all libraries
ring2exe test2.ring -dist -allruntime
After executing the previous command
On Windows we will have : target/windows folder
On Linux we will have : target/linux folder
On macOS we will have : target/macos folder
The previous command will add all of the Ring runtime libraries to our distribution
But we may need only RingAllegro, So it’s better to use the next command
ring2exe test2.ring -dist -allegro -cruntime
This will produce smaller size distribution and will avoid the runtime files that we don’t need!
Also we could use the “-gui” option to hide the console window
So it’s better to use the next command
ring2exe test2.ring -dist -gui -allegro -cruntime
67.5. Building standalone console application 763
Ring Documentation, Release 1.6
67.7 Distributing RingQt Applications
We have test3.ring contains the next code
# Just a simple program to test Ring2EXE Tool!
# Using RingQt
load "guilib.ring"
new qApp {
new qWidget() {
setwindowtitle("Hello, World!")
resize(400,400)
show()
}
exec()
}
To build the executable file and prepare for distributing the GUI application
We use “-dist” option and “-allruntime” to include all libraries
ring2exe test3.ring -dist -allruntime
After executing the previous command
On Windows we will have : target/windows folder
On Linux we will have : target/linux folder
On macOS we will have : target/macos folder
The previous command will add all of the Ring runtime libraries to our distribution
But we may need only RingQt, So it’s better to use the next command
ring2exe test3.ring -dist -qt -cruntime
This will produce smaller size distribution and will avoid the runtime files that we don’t need!
Also we could use the “-gui” option to hide the console window
So it’s better to use the next command
ring2exe test3.ring -dist -gui -qt -cruntime
67.8 Distributing Applications for Mobile using RingQt
To prepare a Qt project for your RingQt application (test3.ring) use the “-mobileqt” option
Example :
ring2exe test3.ring -dist -mobileqt
After executing the previous command, We will have the Qt project in target/mobile/qtproject folder
The main project file will be project.pro which we can open using the Qt Creator IDE.
Also we will have the resource file : project.qrc
Another important file is our C++ main file : main.cpp
67.7. Distributing RingQt Applications 764
Ring Documentation, Release 1.6
67.9 Building the Cards Game for Mobile using RingQt
For a better example, consider building an Android package for the Cards game that comes with the
Ring language in this folder : ring/application/cards
The Cards game folder contains three files
cards.ring : The Game source code
cards.jpg : The image file used by the game
project.qrc : Resource file to be used with the Qt project
The resource file contains the next content
<RCC>
<qresource>
<file>cards.ringo</file>
<file>cards.jpg</file>
</qresource>
</RCC>
We have two files in the resource file
The first file is cards.ringo (The Ring Object File) and the second file is cards.jpg (The image file)
As a start, Ring2EXE will generate this resource file in target/mobile/qtproject/project.qrc
But this file will contains only cards.ringo (That Ring2EXE will generate by calling Ring compiler)
We need to update this resource file to add the image file : cards.jpg
After this update, we copy the resource file to the main application folder
So when we use Ring2EXE again, Our updated resource file will be used!
Now to build the cards game for Mobile
1. Run the next command
ring2exe cards.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
How the Cards game will find the image file ?
RingQt comes with a simple function : AppFile() that we can use to determine the files that we may
access on Desktop or Mobile platforms
The next code from cards.ring
mypic = new QPixmap(AppFile("cards.jpg"))
So all what you need is using AppFile() function around your image files!
67.10 Building the Weight History Application for Mobile using
RingQt
Another example to distribute your application for Mobile Devices using Ring2EXE and Qt
67.9. Building the Cards Game for Mobile using RingQt 765
Ring Documentation, Release 1.6
consider building an Android package for the Weight History application that comes with the
Ring language in this folder : ring/application/weighthistory
The Weight History application folder contains four files
weighthistory.ring : The application source code
weighthistory.db : The SQLite database
project.qrc : The resource file for the Qt project
main.cpp : The main C++ source file for the Qt project
To build the Weight History application for Mobile
1. Run the next command
ring2exe weighthistory.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
The resource file (project.qrc) contains two files
<RCC>
<qresource>
<file>weighthistory.ringo</file>
<file>weighthistory.db</file>
</qresource>
</RCC>
The first file is weighthistory.ringo (Ring Object File - Generated by Ring2EXE by calling Ring compiler)
The database file : weighthistory.db
The main.cpp contains the next little update, To copy the database file from resources to a writable location
on the mobile device
QString path3 ;
path3 = path+"/weighthistory.db";
QFile::copy(":/weighthistory.db",path3);
You will need to do this with database files only!
When we use Ring2EXE, the tool will check for project.qrc and main.cpp, if they exist then your updated
files will be used in target/mobile/qtproject instead of the default version generated by Ring2EXE
So Use Ring2EXE to generate these files, Then copy them to your application folder when you update them.
67.11 Building the Form Designer for Mobile using RingQt
To build the Form Designer application (ring/applications/formdesigner) for Mobile
1. Run the next command
ring2exe formdesigner.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
67.11. Building the Form Designer for Mobile using RingQt 766
Ring Documentation, Release 1.6
in the folder ring/application/formdesigner You will find the resource file : project.qrc
It will be used automatically by Ring2EXE
<RCC>
<qresource>
<file>formdesigner.ringo</file>
<file>image/allevents.png</file>
<file>image/checkbox.png</file>
<file>image/close.png</file>
<file>image/combobox.bmp</file>
<file>image/datepicker.bmp</file>
<file>image/dial.png</file>
<file>image/formdesigner.png</file>
<file>image/frame.png</file>
<file>image/grid.bmp</file>
<file>image/hyperlink.png</file>
<file>image/image.png</file>
<file>image/label.png</file>
<file>image/layout.png</file>
<file>image/lcdnumber.png</file>
<file>image/listview.png</file>
<file>image/lock.png</file>
<file>image/new.png</file>
<file>image/open.png</file>
<file>image/progressbar.png</file>
<file>image/project.png</file>
<file>image/pushbutton.png</file>
<file>image/radiobutton.png</file>
<file>image/save.png</file>
<file>image/saveas.png</file>
<file>image/select.png</file>
<file>image/slider.png</file>
<file>image/spinner.bmp</file>
<file>image/statusbar.png</file>
<file>image/tab.png</file>
<file>image/textarea.png</file>
<file>image/textfield.png</file>
<file>image/timer.png</file>
<file>image/toolbar.png</file>
<file>image/tree.bmp</file>
<file>image/videowidget.png</file>
<file>image/webview.png</file>
</qresource>
</RCC>
As we did in the Cards game, The Form Designer will use the AppFile() function to determine the name of the Image
files.
The next code from ring/applications/formdesigner/mainwindow/formdesignerview.ring
func CreateToolBar
aBtns = [
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/new.png"))
setclickevent(Method(:NewAction))
settooltip("New File")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/open.png"))
67.11. Building the Form Designer for Mobile using RingQt 767
Ring Documentation, Release 1.6
setclickevent(Method(:OpenAction))
settooltip("Open File")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/save.png"))
setclickevent(Method(:SaveAction))
settooltip("Save")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/saveas.png"))
setclickevent(Method(:SaveAsAction))
settooltip("Save As")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/close.png"))
setclickevent(Method(:ExitAction))
settooltip("Exit")
}
]
tool1 = win.addtoolbar("files") {
for x in aBtns { addwidget(x) addseparator() }
}
From this example, We know that we can use sub folders for images.
67.12 Creating the Qt resource file using Folder2qrc
When we have large RingQt project that contains a lot of images and files, We need to add these files to the resource
file ( *.qrc ) when distributing applications for Mobile devices.
Instead of adding these files one by one, Ring 1.6 comes with a simple tool that save our time, It’s called Folder2qrc.
Example:
folder2qrc formdesigner.ring
We determine the main source file while we are in the application folder, and Folder2qrc will check all of the files in
the current folder and sub folders, Then add them to the resource file after the mainfile.ringo (In our example this will
be formdesigner.ringo)
The output file will be : project.qrc
You can open it and remove the files that you don’t need in the resources!
67.13 Important Information about Ring2EXE
• Using Ring2EXE to prepare distribution will delete all of the files in the old distribution
for example, if you have target/windows folder then used
ring2exe test3.ring -dist -allruntime
The files in target/windows will be deleted before adding the files again
This is important when you prepare a distribution for Mobile devices
67.12. Creating the Qt resource file using Folder2qrc 768
Ring Documentation, Release 1.6
ring2exe test3.ring -dist -mobileqt
If you modified the resource file : project.qrc or the main file : main.cpp
Don’t forget to copy them to the application folder!
So Ring2EXE can use the updated version if you tried the previous command again!
• Ring2EXE is written in Ring, and you can read the source code from
https://github.com/ring-lang/ring/blob/master/ring2exe/ring2exe.ring
• The libraries information are stored in a separated file, So this file can be updated in the future
automatically to support new libraries
https://github.com/ring-lang/ring/blob/master/ring2exe/ring2exe.data
67.13. Important Information about Ring2EXE 769
CHAPTER
SIXTYEIGHT
LOW LEVEL FUNCTIONS
In this chapter we will learn about the low level functions provided by Ring
• callgc()
• varptr()
• space()
• nullpointer()
• object2pointer()
• pointer2object()
• ptrcmp()
• ringvm_cfunctionslist()
• ringvm_functionslist()
• ringvm_classeslist()
• ringvm_packageslist()
• ringvm_memorylist()
• ringvm_calllist()
• ringvm_fileslist()
• ringvm_settrace()
• ringvm_tracedata()
• ringvm_traceevent()
• ringvm_tracefunc()
• ringvm_scopescount()
• ringvm_evalinscope()
• ringvm_passerror()
• ringvm_hideerrorMsg()
• ringvm_callfunc()
770
Ring Documentation, Release 1.6
68.1 callgc() function
Use this function to force calling the garbage collector during function execution when you use a loop that create temp.
variables that you don’t free using the assignment operation.
It’s very rare to need this function but it’s useful when you create something like event-loop for your game engine and
start creating lists on the fly when you call functions.
Example
While True
# process events
# call functions using temp. lists like myfunc(["temp list"])
# call the garbage collector
callgc()
End
Tip: In Ring the garbage collector works automatically in the end of function execution or when you use the assign-
ment statement.
68.2 varptr() function
Use the varptr() function when you need to pass a pointer to a C/C++ function.
Syntax:
varptr(cVariableName,cPointerType) —> Low Level Object (C Pointer)
example:
r = 10
z = 20
see r + nl
see varptr("r","int")
see varptr("z","int")
Output:
10
00E3C740
int
2
00E3BEC0
int
2
Note: the low level object is a list contains three items (The Pointer, The Type, The Status)
68.3 space() function
Use the space function to allocate a specific number of bytes in Memory.
68.1. callgc() function 771
Ring Documentation, Release 1.6
Syntax:
Space(nBytesCount) ---> String
Example:
mystring = space(200)
See "String Size : " + len(mystring) + nl
See "String : " + mystring + nl
See "String Pointer : "
See varptr("mystring","char *")
Output:
String Size : 200
String :
String Pointer : 00FF8FE8
char *
2
Note: You may need the space() and VarPtr() functions to pass buffers to C functions.
68.4 nullpointer() function
You may need to pass the NULL pointer to a C function that may expect a pointer as parameter and accept NULL
pointers for optional parameters.
Example:
The next example uses the SDL_BlitSurface() function from the LibSDL Library through RingSDL The function
accept SDL_Rect pointers in the second and the last parameter. Also the function accept NULL pointers, so we can
pass them using the NULLPointer() Function.
SDL_BlitSurface(text, nullpointer(), surface, nullpointer())
Note: The previous code doesn’t work alone, you need to learn how to use RingSDL first.
Tip: We can pass NULL as parameter instead of using NULLPointer()
68.5 object2pointer() function
Use this function to get a C pointer for Ring lists and objects
Syntax:
object2pointer(List|Object) --> Low Level Object ( C Pointer )
68.6 pointer2object() function
Use this function to get the Ring list and/or object from the low level object (C Pointer)
68.4. nullpointer() function 772

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.5.4 book - Part 70 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 90 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 72 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 10 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4.1 book - Part 16 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
PDF
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Applitools
 
PDF
The Ring programming language version 1.5.3 book - Part 13 of 184
Mahmoud Samir Fayed
 
PDF
Kafka Streams: Perfectly Balanced as all things should be
confluent
 
PDF
Introducción a git y GitHub
Lucas Videla
 
PPTX
{'python': 'dict'}
nybon
 
PDF
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Roland Tritsch
 
PDF
Big query - Command line tools and Tips - (MOSG)
Soshi Nemoto
 
PDF
Exploring Google (Cloud) APIs with Python & JavaScript
wesley chun
 
PDF
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Rajmahendra Hegde
 
PPTX
LOD and Culling Systems That Scale - Unite LA
Unity Technologies
 
PPTX
MeteorJS Meetup
Involved IT
 
PDF
How to operate containerized OpenStack
Nalee Jang
 
PDF
10 Cool Facts about Gradle
Evgeny Goldin
 
PDF
Floating point
Mykhailo Kotsur
 
The Ring programming language version 1.5.4 book - Part 70 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 90 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 72 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 10 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 16 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Applitools
 
The Ring programming language version 1.5.3 book - Part 13 of 184
Mahmoud Samir Fayed
 
Kafka Streams: Perfectly Balanced as all things should be
confluent
 
Introducción a git y GitHub
Lucas Videla
 
{'python': 'dict'}
nybon
 
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Roland Tritsch
 
Big query - Command line tools and Tips - (MOSG)
Soshi Nemoto
 
Exploring Google (Cloud) APIs with Python & JavaScript
wesley chun
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Rajmahendra Hegde
 
LOD and Culling Systems That Scale - Unite LA
Unity Technologies
 
MeteorJS Meetup
Involved IT
 
How to operate containerized OpenStack
Nalee Jang
 
10 Cool Facts about Gradle
Evgeny Goldin
 
Floating point
Mykhailo Kotsur
 

Similar to The Ring programming language version 1.6 book - Part 80 of 189 (20)

PDF
The Ring programming language version 1.7 book - Part 82 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 89 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 10 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 13 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 83 of 212
Mahmoud Samir Fayed
 
PDF
node-webkit : Make a magic from your a desktop app to desktop app!
욱진 양
 
PDF
The Ring programming language version 1.9 book - Part 81 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 14 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 17 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 68 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 15 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 9 of 210
Mahmoud Samir Fayed
 
PDF
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
Alexandre Gouaillard
 
PDF
ContainerDayVietnam2016: Django Development with Docker
Docker-Hanoi
 
PDF
The Ring programming language version 1.5.2 book - Part 15 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 14 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 10 of 88
Mahmoud Samir Fayed
 
PDF
DEF CON 27 - workshop - ISAAC EVANS - discover exploit and eradicate entire v...
Felipe Prado
 
PPT
Intro to Android Programming
Peter van der Linden
 
The Ring programming language version 1.7 book - Part 82 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 89 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 10 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 13 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 83 of 212
Mahmoud Samir Fayed
 
node-webkit : Make a magic from your a desktop app to desktop app!
욱진 양
 
The Ring programming language version 1.9 book - Part 81 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 14 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 17 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 68 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 15 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 9 of 210
Mahmoud Samir Fayed
 
IIT-RTC 2017 Qt WebRTC Tutorial (Qt Janus Client)
Alexandre Gouaillard
 
ContainerDayVietnam2016: Django Development with Docker
Docker-Hanoi
 
The Ring programming language version 1.5.2 book - Part 15 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 14 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 10 of 88
Mahmoud Samir Fayed
 
DEF CON 27 - workshop - ISAAC EVANS - discover exploit and eradicate entire v...
Felipe Prado
 
Intro to Android Programming
Peter van der Linden
 
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 191 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 191 of 212
Mahmoud Samir Fayed
 
Ad

Recently uploaded (20)

PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
July Patch Tuesday
Ivanti
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 

The Ring programming language version 1.6 book - Part 80 of 189

  • 1. Ring Documentation, Release 1.6 67.5 Building standalone console application Using the “-static” option we can build executable console application So we don’t have to use ring.dll, ring.so or ring.dylib This avoid only the need to Ring dynamic link library If you are using another libraries, You will need to include it with your application. ring2exe test.ring -static 67.6 Distributing RingAllegro Applications We have test2.ring contains the next code # Just a simple program to test Ring2EXE Tool! # Using RingAllegro 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" } To build the executable file and prepare for distributing the Game We use “-dist” option and “-allruntime” to include all libraries ring2exe test2.ring -dist -allruntime After executing the previous command On Windows we will have : target/windows folder On Linux we will have : target/linux folder On macOS we will have : target/macos folder The previous command will add all of the Ring runtime libraries to our distribution But we may need only RingAllegro, So it’s better to use the next command ring2exe test2.ring -dist -allegro -cruntime This will produce smaller size distribution and will avoid the runtime files that we don’t need! Also we could use the “-gui” option to hide the console window So it’s better to use the next command ring2exe test2.ring -dist -gui -allegro -cruntime 67.5. Building standalone console application 763
  • 2. Ring Documentation, Release 1.6 67.7 Distributing RingQt Applications We have test3.ring contains the next code # Just a simple program to test Ring2EXE Tool! # Using RingQt load "guilib.ring" new qApp { new qWidget() { setwindowtitle("Hello, World!") resize(400,400) show() } exec() } To build the executable file and prepare for distributing the GUI application We use “-dist” option and “-allruntime” to include all libraries ring2exe test3.ring -dist -allruntime After executing the previous command On Windows we will have : target/windows folder On Linux we will have : target/linux folder On macOS we will have : target/macos folder The previous command will add all of the Ring runtime libraries to our distribution But we may need only RingQt, So it’s better to use the next command ring2exe test3.ring -dist -qt -cruntime This will produce smaller size distribution and will avoid the runtime files that we don’t need! Also we could use the “-gui” option to hide the console window So it’s better to use the next command ring2exe test3.ring -dist -gui -qt -cruntime 67.8 Distributing Applications for Mobile using RingQt To prepare a Qt project for your RingQt application (test3.ring) use the “-mobileqt” option Example : ring2exe test3.ring -dist -mobileqt After executing the previous command, We will have the Qt project in target/mobile/qtproject folder The main project file will be project.pro which we can open using the Qt Creator IDE. Also we will have the resource file : project.qrc Another important file is our C++ main file : main.cpp 67.7. Distributing RingQt Applications 764
  • 3. Ring Documentation, Release 1.6 67.9 Building the Cards Game for Mobile using RingQt For a better example, consider building an Android package for the Cards game that comes with the Ring language in this folder : ring/application/cards The Cards game folder contains three files cards.ring : The Game source code cards.jpg : The image file used by the game project.qrc : Resource file to be used with the Qt project The resource file contains the next content <RCC> <qresource> <file>cards.ringo</file> <file>cards.jpg</file> </qresource> </RCC> We have two files in the resource file The first file is cards.ringo (The Ring Object File) and the second file is cards.jpg (The image file) As a start, Ring2EXE will generate this resource file in target/mobile/qtproject/project.qrc But this file will contains only cards.ringo (That Ring2EXE will generate by calling Ring compiler) We need to update this resource file to add the image file : cards.jpg After this update, we copy the resource file to the main application folder So when we use Ring2EXE again, Our updated resource file will be used! Now to build the cards game for Mobile 1. Run the next command ring2exe cards.ring -dist -mobileqt 2. Open target/mobile/qtproject/project.pro using Qt creator 3. Build and Run using Qt Creator How the Cards game will find the image file ? RingQt comes with a simple function : AppFile() that we can use to determine the files that we may access on Desktop or Mobile platforms The next code from cards.ring mypic = new QPixmap(AppFile("cards.jpg")) So all what you need is using AppFile() function around your image files! 67.10 Building the Weight History Application for Mobile using RingQt Another example to distribute your application for Mobile Devices using Ring2EXE and Qt 67.9. Building the Cards Game for Mobile using RingQt 765
  • 4. Ring Documentation, Release 1.6 consider building an Android package for the Weight History application that comes with the Ring language in this folder : ring/application/weighthistory The Weight History application folder contains four files weighthistory.ring : The application source code weighthistory.db : The SQLite database project.qrc : The resource file for the Qt project main.cpp : The main C++ source file for the Qt project To build the Weight History application for Mobile 1. Run the next command ring2exe weighthistory.ring -dist -mobileqt 2. Open target/mobile/qtproject/project.pro using Qt creator 3. Build and Run using Qt Creator The resource file (project.qrc) contains two files <RCC> <qresource> <file>weighthistory.ringo</file> <file>weighthistory.db</file> </qresource> </RCC> The first file is weighthistory.ringo (Ring Object File - Generated by Ring2EXE by calling Ring compiler) The database file : weighthistory.db The main.cpp contains the next little update, To copy the database file from resources to a writable location on the mobile device QString path3 ; path3 = path+"/weighthistory.db"; QFile::copy(":/weighthistory.db",path3); You will need to do this with database files only! When we use Ring2EXE, the tool will check for project.qrc and main.cpp, if they exist then your updated files will be used in target/mobile/qtproject instead of the default version generated by Ring2EXE So Use Ring2EXE to generate these files, Then copy them to your application folder when you update them. 67.11 Building the Form Designer for Mobile using RingQt To build the Form Designer application (ring/applications/formdesigner) for Mobile 1. Run the next command ring2exe formdesigner.ring -dist -mobileqt 2. Open target/mobile/qtproject/project.pro using Qt creator 3. Build and Run using Qt Creator 67.11. Building the Form Designer for Mobile using RingQt 766
  • 5. Ring Documentation, Release 1.6 in the folder ring/application/formdesigner You will find the resource file : project.qrc It will be used automatically by Ring2EXE <RCC> <qresource> <file>formdesigner.ringo</file> <file>image/allevents.png</file> <file>image/checkbox.png</file> <file>image/close.png</file> <file>image/combobox.bmp</file> <file>image/datepicker.bmp</file> <file>image/dial.png</file> <file>image/formdesigner.png</file> <file>image/frame.png</file> <file>image/grid.bmp</file> <file>image/hyperlink.png</file> <file>image/image.png</file> <file>image/label.png</file> <file>image/layout.png</file> <file>image/lcdnumber.png</file> <file>image/listview.png</file> <file>image/lock.png</file> <file>image/new.png</file> <file>image/open.png</file> <file>image/progressbar.png</file> <file>image/project.png</file> <file>image/pushbutton.png</file> <file>image/radiobutton.png</file> <file>image/save.png</file> <file>image/saveas.png</file> <file>image/select.png</file> <file>image/slider.png</file> <file>image/spinner.bmp</file> <file>image/statusbar.png</file> <file>image/tab.png</file> <file>image/textarea.png</file> <file>image/textfield.png</file> <file>image/timer.png</file> <file>image/toolbar.png</file> <file>image/tree.bmp</file> <file>image/videowidget.png</file> <file>image/webview.png</file> </qresource> </RCC> As we did in the Cards game, The Form Designer will use the AppFile() function to determine the name of the Image files. The next code from ring/applications/formdesigner/mainwindow/formdesignerview.ring func CreateToolBar aBtns = [ new qtoolbutton(win) { setbtnimage(self,AppFile("image/new.png")) setclickevent(Method(:NewAction)) settooltip("New File") } , new qtoolbutton(win) { setbtnimage(self,AppFile("image/open.png")) 67.11. Building the Form Designer for Mobile using RingQt 767
  • 6. Ring Documentation, Release 1.6 setclickevent(Method(:OpenAction)) settooltip("Open File") } , new qtoolbutton(win) { setbtnimage(self,AppFile("image/save.png")) setclickevent(Method(:SaveAction)) settooltip("Save") } , new qtoolbutton(win) { setbtnimage(self,AppFile("image/saveas.png")) setclickevent(Method(:SaveAsAction)) settooltip("Save As") } , new qtoolbutton(win) { setbtnimage(self,AppFile("image/close.png")) setclickevent(Method(:ExitAction)) settooltip("Exit") } ] tool1 = win.addtoolbar("files") { for x in aBtns { addwidget(x) addseparator() } } From this example, We know that we can use sub folders for images. 67.12 Creating the Qt resource file using Folder2qrc When we have large RingQt project that contains a lot of images and files, We need to add these files to the resource file ( *.qrc ) when distributing applications for Mobile devices. Instead of adding these files one by one, Ring 1.6 comes with a simple tool that save our time, It’s called Folder2qrc. Example: folder2qrc formdesigner.ring We determine the main source file while we are in the application folder, and Folder2qrc will check all of the files in the current folder and sub folders, Then add them to the resource file after the mainfile.ringo (In our example this will be formdesigner.ringo) The output file will be : project.qrc You can open it and remove the files that you don’t need in the resources! 67.13 Important Information about Ring2EXE • Using Ring2EXE to prepare distribution will delete all of the files in the old distribution for example, if you have target/windows folder then used ring2exe test3.ring -dist -allruntime The files in target/windows will be deleted before adding the files again This is important when you prepare a distribution for Mobile devices 67.12. Creating the Qt resource file using Folder2qrc 768
  • 7. Ring Documentation, Release 1.6 ring2exe test3.ring -dist -mobileqt If you modified the resource file : project.qrc or the main file : main.cpp Don’t forget to copy them to the application folder! So Ring2EXE can use the updated version if you tried the previous command again! • Ring2EXE is written in Ring, and you can read the source code from https://github.com/ring-lang/ring/blob/master/ring2exe/ring2exe.ring • The libraries information are stored in a separated file, So this file can be updated in the future automatically to support new libraries https://github.com/ring-lang/ring/blob/master/ring2exe/ring2exe.data 67.13. Important Information about Ring2EXE 769
  • 8. CHAPTER SIXTYEIGHT LOW LEVEL FUNCTIONS In this chapter we will learn about the low level functions provided by Ring • callgc() • varptr() • space() • nullpointer() • object2pointer() • pointer2object() • ptrcmp() • ringvm_cfunctionslist() • ringvm_functionslist() • ringvm_classeslist() • ringvm_packageslist() • ringvm_memorylist() • ringvm_calllist() • ringvm_fileslist() • ringvm_settrace() • ringvm_tracedata() • ringvm_traceevent() • ringvm_tracefunc() • ringvm_scopescount() • ringvm_evalinscope() • ringvm_passerror() • ringvm_hideerrorMsg() • ringvm_callfunc() 770
  • 9. Ring Documentation, Release 1.6 68.1 callgc() function Use this function to force calling the garbage collector during function execution when you use a loop that create temp. variables that you don’t free using the assignment operation. It’s very rare to need this function but it’s useful when you create something like event-loop for your game engine and start creating lists on the fly when you call functions. Example While True # process events # call functions using temp. lists like myfunc(["temp list"]) # call the garbage collector callgc() End Tip: In Ring the garbage collector works automatically in the end of function execution or when you use the assign- ment statement. 68.2 varptr() function Use the varptr() function when you need to pass a pointer to a C/C++ function. Syntax: varptr(cVariableName,cPointerType) —> Low Level Object (C Pointer) example: r = 10 z = 20 see r + nl see varptr("r","int") see varptr("z","int") Output: 10 00E3C740 int 2 00E3BEC0 int 2 Note: the low level object is a list contains three items (The Pointer, The Type, The Status) 68.3 space() function Use the space function to allocate a specific number of bytes in Memory. 68.1. callgc() function 771
  • 10. Ring Documentation, Release 1.6 Syntax: Space(nBytesCount) ---> String Example: mystring = space(200) See "String Size : " + len(mystring) + nl See "String : " + mystring + nl See "String Pointer : " See varptr("mystring","char *") Output: String Size : 200 String : String Pointer : 00FF8FE8 char * 2 Note: You may need the space() and VarPtr() functions to pass buffers to C functions. 68.4 nullpointer() function You may need to pass the NULL pointer to a C function that may expect a pointer as parameter and accept NULL pointers for optional parameters. Example: The next example uses the SDL_BlitSurface() function from the LibSDL Library through RingSDL The function accept SDL_Rect pointers in the second and the last parameter. Also the function accept NULL pointers, so we can pass them using the NULLPointer() Function. SDL_BlitSurface(text, nullpointer(), surface, nullpointer()) Note: The previous code doesn’t work alone, you need to learn how to use RingSDL first. Tip: We can pass NULL as parameter instead of using NULLPointer() 68.5 object2pointer() function Use this function to get a C pointer for Ring lists and objects Syntax: object2pointer(List|Object) --> Low Level Object ( C Pointer ) 68.6 pointer2object() function Use this function to get the Ring list and/or object from the low level object (C Pointer) 68.4. nullpointer() function 772