The Ring Programming Language Version 1.5 Book - Part 12 of 180
The Ring Programming Language Version 1.5 Book - Part 12 of 180
EIGHT
In this chapter we will learn about the changes and new features in Ring 1.2 release.
PtrCmp() Function is a new function that compare between C pointers like the GUI objects.
PrevFileName() Function is added to return the previous active source file name.
RingVM_CFunctionsList() Function is added to return a list of functions written in C.
RingVM_FunctionsList() Function is added to return a list of functions written in Ring.
RingVM_ClassesList() Function is added to return a list of Classes.
RingVM_PackagesList() Function is added to return a list of Packages.
RingVM_MemoryList() Function is added to return a list of Memory Scopes and Variables.
RingVM_CallList() Function is added to return a list of the functions call list.
RingVM_FilesList() Function is added to return a list of the Ring Files.
Example:
86
Ring Documentation, Release 1.5
fp = fopen("ptrcmp.ring","r")
fp2 = fp
fp3 = fopen("ptrcmp.ring","r")
see ptrcmp(fp,fp2) + nl
see ptrcmp(fp,fp3) + nl
fclose(fp)
fclose(fp3)
Output:
1
0
Output:
0
1
Example:
The next function in stdlib.ring uses the PrevFileName() to know if the file of the caller function is the main source
file of the program or not.
Func IsMainSourceFile
if PrevFileName() = sysargv[2]
return true
ok
return false
The find() function is updated to support searching in lists using C pointers like GUI Objects.
The type() function is updated to display the C pointers types (like the GUI Object Class Name).
The Ring Notepad will save the current line number of opened files to be restored when we switch between files.
Also Ring Notepad will ask the user to save the file if the file content is changed when the user switch between files.
RingQt classes are updated to include methods to get events (The code that will be executed when an event is fired).
This is necessary to enable/disable events for some time or to get the events information.
For example the next code disable an event then call a method then enable the event again.
cEvent = oView.oListResult.getCurrentItemChangedEvent()
oView.oListResult.setCurrentItemChangedEvent("")
FindValueAction() # Call Method while an event is disabled
oView.oListResult.setCurrentItemChangedEvent(cEvent)
Also the QAllEvents class is updated where we can set the output from the event function to be true or false using a
new method added to the class called setEventOutput.
Load "guilib.ring"
func pMove
win.setWindowTitle("xxxx")
oFilter.setEventOutput(False)
Ring 1.2 comes with the Objects library for RingQt applications. Instead of using global variables for windows
objects and connecting events to objects using the object name, the Objects Library will manage the GUI objects and
will provide a more natural API to quickly create one or many windows from the same class and the library provide
a way to quickly set methods to be executed when an event is fired. Also the library provide a natural interface to
quickly use the parent or the caller windows from the child or sub windows.
The Objects Library is designed to be used with the MVC Design Pattern.
The Objects Library is merged in RingQt so you can use it directly when you use RingQt
Example :
load "guilib.ring"
new qApp {
open_window( :MainWindowController )
exec()
}
8.7 RingLibCurl
The LibCurl library is used starting from Ring 1.0 for the Download() and SendEmail() functions implementation. In
Ring 1.2 more functions are added to provide a powerful library (RingLibCurl) around LibCurl.
Example:
load "libcurl.ring"
curl = curl_easy_init()
cPostThis = "page=4&Number1=4&Number2=5"
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/ringapp/index.ring?page=3")
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cPostThis)
8.7. RingLibCurl 89
Ring Documentation, Release 1.5
curl_easy_perform(curl)
curl_easy_cleanup(curl)
The Call command is updated to support calling functions from object attributes also (not only variables).
For example the next code from the Stars Fighter Game
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_Space)
In Ring 1.2 the Ring compiler is updated to include the Display Warnings option (-w)
Example:
load "stdlib.ring"
load "stdlib.ring"
compiling the program using the Display Warnings option will display the file duplication warning, While without that
option the error will pass silent.
This is a warning (not an error) because in large projects you may use the same file more than one time. For example
its common to start each file with the next code. where the function IsMainSourceFile() is part from the stdlib.ring
load "stdlib.ring"
if IsMainSourceFile()
// Testing
ok
Ring 1.2 is more stable, We discovered and fixed more bugs during Ring usage everyday in practical projects. Some
functions are optimized to be faster like the SubStr() function. Also the documentation is more better.
NINE
In this chapter we will learn about the changes and new features in Ring 1.1 release.
Ring is an innovative language because of its compact syntax, smart implementation (small, transparent & visual) and
its ability to create declarative and natural domain specific languages in a fraction of time.
This release add support for calling methods when an expression is evaluated
check this example:
# Natural Code
new program {
Accept 2 numbers then print the sum
}
92
Ring Documentation, Release 1.5
class program
# Keywords
Accept=0 numbers=0 then=0 print=0 the=0 sum=0
# Execution
func braceexpreval x
value = x
func getnumbers
for x=1 to value
see "Enter Number ("+x+") :" give nNumber
aNumbers + nNumber
next
func getsum
nSUm = 0
for x in aNumbers nSum+= x next
see "The Sum : " + nSum
private
value=0 aNumbers=[]
Output:
Enter Number (1) :3
Enter Number (2) :4
The Sum : 7
This feature enable you to distribute your applications without distributing the source code. Also it makes application
distribution a simple process where you get one Ring object file for the complete project (many source code files).
Also using Ring object file remove the loading time required for compiling the application.
Check the command line options chapter to know more about this feature.
9.4 Syntax Flexibility and different styles for I/O and Control Struc-
tures
Programmers are sensitive to the programming language syntax. Great programmers know how to work using many
different styles but each programmer may have his/her favorite style.
Each programming language comes with a style that you may like or not. Ring is just one of these languages, but as a
response to many programmers asking for a better syntax we decided to provide more options.
Also some of these features are very necessary for Natural Language Programming.
Example :
We have two commands to change language keywords and operators.
ChangeRingOperator + plus
ChangeRingKeyword see print
Print 5 plus 5
ChangeRingOperator plus +
ChangeRingKeyword print see
Example :
Load "stdlib.ring"
Put "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
Switch nOption
Case 1
Put "Enter your name : "
Get name
Put "Hello " + name + nl
Case 2
Put "Sample : using while loop" + nl
Case 3
Bye
Else
Put "bad option..." + nl
End
End
Example :
Load "stdlib.ring"
While True {
print("
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
9.4. Syntax Flexibility and different styles for I/O and Control Structures 94