SlideShare a Scribd company logo
Ring Documentation, Release 1.10
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Function
Line Number : 9
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 44
File Name : test1.ring
Function Name : mymethod
Method or Function : Method
==========================================
Message from mymethod
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
9.14. Ring VM - Tracing Functions 128
Ring Documentation, Release 1.10
Trace Event : Before C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 9
File Name : test1.ring
Function Name : ismethod
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 11
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
9.15 Trace Library and Interactive Debugger
Ring 1.5 comes with the Trace Library and the Interactive Debugger
Using this library we can trace events, execute programs line by line, open the Interactive Debugger when an error
happens or at breakpoints.
Example:
The next example uses a Breakpoint to open the Interactive Debugger!
load "tracelib.ring"
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
Screen Shots:
We have the Interactive Debugger at the Breakpoint!
9.15. Trace Library and Interactive Debugger 129
Ring Documentation, Release 1.10
We can print the variables values
We can change the variables values then continue execution
We can run the Interactive Debugger in the Output Window
9.15. Trace Library and Interactive Debugger 130
Ring Documentation, Release 1.10
9.16 More Syntax Flexibility
• Using braces { } in Packages/Classes/Functions
Example:
load "stdlib.ring"
import mypackage
new myclass {
myfunc()
}
package mypackage
{
class myclass
{
func myfunc
{
print("Hello, World!n")
}
}
}
• Using ‘end’ keyword after Packages/Classes/Functions
Example:
import mypackage
new myclass {
myfunc()
}
9.16. More Syntax Flexibility 131
Ring Documentation, Release 1.10
package mypackage
class myclass
def myfunc
put "Hello, World!"
end
end
end
• Using ‘endpackage’/’endclass’/’endfunc’ keywords after Packages/Classes/Functions
Example:
import mypackage
new myclass { myfunc() }
package mypackage
class myclass
func myfunc
see "welcome" + nl
endfunc
endclass
endpackage
9.17 Type Hints Library
Ring 1.5 comes with the Type Hints library
Using this library we can add the type information to the source code which will be very useful for tools like
• Code Editors
• Static-Analysis
Example:
load "typehints.ring"
see sum(3,4) + nl ;
see sayHello("Mahmoud");
int func sum(int x,int y) {
return x+y ;
}
string func sayHello(string name) {
return "Hello " + name ;
}
The library is very powerful and support the User types (Classes) automatically!
Example:
load "typehints.ring"
import mypackage
test() { main([:one,:two,:three]) }
9.17. Type Hints Library 132
Ring Documentation, Release 1.10
myclass func test() {
see "Testing User Types!" + nl
return new myclass
}
package mypackage {
public class myclass {
public static void func main(list args) {
see "welcome" + nl
see args
}
}
}
Also You can use the types inside the code (not only the function prototype)
Example:
load "typehints.ring"
int sum = sum(3,4)
string msg = sayHello("Mahmoud")
see "Sum = " + sum + nl + msg + nl
int func sum(int x,int y) {
return x+y ;
}
string func sayHello(string name) {
return "Hello " + name ;
}
Rules:
• To use the types in the function prototype, You must use ‘(‘ and ‘)’ around parameters
• To use the types in the function code, You must set the variable value (Assignment).
Note: Ring is a dynamic language, No type checking will be done by the compiler.
9.18 Better Quality
Based on Ring usage every day in practical projects
Ring 1.5 is more stable and more productive!
We are adding features based on clear vision and practical needs.
Also the documentation is better.
9.19 What is new in Ring 1.5.1?
• Better Documentation
9.18. Better Quality 133
Ring Documentation, Release 1.10
• StdLib - Factorial() function update
• RingVM - Better code for clearing the stack in the Class Region.
• Sample : 3D Cube (OpenGL) + Texture Image using GameLib (RingAllegro)
Source Code:
load "gamelib.ring"
load "opengl21lib.ring"
func main
new GraphicsApp {
start()
}
class GraphicsApp from GraphicsAppBase
TITLE = "Ring Cube"
bitmap texture
xrot = 0.0
yrot = 0.0
zrot = 0.0
func loadresources
bitmap = al_load_bitmap("ring.bmp")
texture = al_get_opengl_texture(bitmap)
func destroyResources
al_destroy_bitmap(bitmap)
func drawScene
w = 800 h = 600
ratio = w / h
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45,ratio,1,100)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glEnable(GL_TEXTURE_2D)
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.5)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
9.19. What is new in Ring 1.5.1? 134
Ring Documentation, Release 1.10
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(zrot,0.0,0.0,1.0);
glBindTexture(GL_TEXTURE_2D, texture)
glBegin(GL_QUADS)
// Front Face
glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
// Back Face
glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
// Top Face
glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, 1.0, 1.0)
glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, 1.0, 1.0)
glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
// Bottom Face
glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, -1.0, -1.0)
glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, -1.0, -1.0)
glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
// Right face
glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
// Left Face
glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
glEnd()
xrot += 0.3
yrot += 0.2
zrot += 0.4
class GraphicsAppBase
display event_queue ev timeout
timer redraw = true
FPS = 60
SCREEN_W = 800
SCREEN_H = 600
KEY_UP = 1
9.19. What is new in Ring 1.5.1? 135
Ring Documentation, Release 1.10
KEY_DOWN = 2
KEY_LEFT = 3
KEY_RIGHT = 4
Key = [false,false,false,false]
TITLE = "Graphics Application"
func start
SetUp()
loadResources()
eventsLoop()
destroy()
func setup
al_init()
al_init_image_addon()
al_set_new_display_flags(ALLEGRO_OPENGL)
display = al_create_display(SCREEN_W,SCREEN_H)
al_set_Window_title(display,TITLE)
al_clear_to_color(al_map_rgb(0,0,0))
event_queue = al_create_event_queue()
al_register_event_source(event_queue,
al_get_display_event_source(display))
ev = al_new_allegro_event()
timeout = al_new_allegro_timeout()
al_init_timeout(timeout, 0.06)
timer = al_create_timer(1.0 / FPS)
al_register_event_source(event_queue,
al_get_timer_event_source(timer))
al_start_timer(timer)
al_install_mouse()
al_register_event_source(event_queue,
al_get_mouse_event_source())
al_install_keyboard()
al_register_event_source(event_queue,
al_get_keyboard_event_source())
func eventsLoop
while true
al_wait_for_event_until(event_queue, ev, timeout)
switch al_get_allegro_event_type(ev)
on ALLEGRO_EVENT_DISPLAY_CLOSE
exit
on ALLEGRO_EVENT_TIMER
redraw = true
on ALLEGRO_EVENT_MOUSE_AXES
mouse_x = al_get_allegro_event_mouse_x(ev)
mouse_y = al_get_allegro_event_mouse_y(ev)
on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
mouse_x = al_get_allegro_event_mouse_x(ev)
mouse_y = al_get_allegro_event_mouse_y(ev)
on ALLEGRO_EVENT_MOUSE_BUTTON_UP
exit
on ALLEGRO_EVENT_KEY_DOWN
9.19. What is new in Ring 1.5.1? 136
Ring Documentation, Release 1.10
switch al_get_allegro_event_keyboard_keycode(ev)
on ALLEGRO_KEY_UP
key[KEY_UP] = true
on ALLEGRO_KEY_DOWN
key[KEY_DOWN] = true
on ALLEGRO_KEY_LEFT
key[KEY_LEFT] = true
on ALLEGRO_KEY_RIGHT
key[KEY_RIGHT] = true
off
on ALLEGRO_EVENT_KEY_UP
switch al_get_allegro_event_keyboard_keycode(ev)
on ALLEGRO_KEY_UP
key[KEY_UP] = false
on ALLEGRO_KEY_DOWN
key[KEY_DOWN] = false
on ALLEGRO_KEY_LEFT
key[KEY_LEFT] = false
on ALLEGRO_KEY_RIGHT
key[KEY_RIGHT] = false
on ALLEGRO_KEY_ESCAPE
exit
off
off
if redraw and al_is_event_queue_empty(event_queue)
redraw = false
drawScene()
al_flip_display()
ok
callgc()
end
func destroy
destroyResources()
al_destroy_timer(timer)
al_destroy_allegro_event(ev)
al_destroy_allegro_timeout(timeout)
al_destroy_event_queue(event_queue)
al_destroy_display(display)
func loadresources
func drawScene
func destroyResources
Screen Shot:
9.19. What is new in Ring 1.5.1? 137

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.5.3 book - Part 88 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 82 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 87 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 9 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 41 of 189
Mahmoud Samir Fayed
 
PPT
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
PDF
Promise: async programming hero
The Software House
 
PDF
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
PDF
Java 7 LavaJUG
julien.ponge
 
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
PDF
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
PDF
The Ring programming language version 1.5.2 book - Part 9 of 181
Mahmoud Samir Fayed
 
PDF
JVM Mechanics: Understanding the JIT's Tricks
Doug Hawkins
 
PDF
响应式编程及框架
jeffz
 
PDF
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
PPTX
The secret unit testing tools no one ever told you about
Dror Helper
 
PPTX
NetBeans Plugin Development: JRebel Experience Report
Anton Arhipov
 
PDF
The Ring programming language version 1.5.1 book - Part 37 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 91 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 88 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 82 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 87 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 9 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 41 of 189
Mahmoud Samir Fayed
 
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Promise: async programming hero
The Software House
 
The Ring programming language version 1.6 book - Part 11 of 189
Mahmoud Samir Fayed
 
Java 7 LavaJUG
julien.ponge
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
The Ring programming language version 1.5.2 book - Part 9 of 181
Mahmoud Samir Fayed
 
JVM Mechanics: Understanding the JIT's Tricks
Doug Hawkins
 
响应式编程及框架
jeffz
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
The secret unit testing tools no one ever told you about
Dror Helper
 
NetBeans Plugin Development: JRebel Experience Report
Anton Arhipov
 
The Ring programming language version 1.5.1 book - Part 37 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 91 of 196
Mahmoud Samir Fayed
 

Similar to The Ring programming language version 1.10 book - Part 17 of 212 (20)

PDF
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 78 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 16 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 15 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 101 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 15 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 13 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 83 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 12 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 93 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
PDF
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
PDF
The Ring programming language version 1.8 book - Part 88 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
PPTX
Intro to Javascript
Anjan Banda
 
PDF
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 12 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 78 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 16 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 15 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 101 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 188 of 194
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 15 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 13 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 83 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 12 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 93 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 7 of 181
Mahmoud Samir Fayed
 
Java 8 new features or the ones you might actually use
Sharon Rozinsky
 
The Ring programming language version 1.8 book - Part 88 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
Intro to Javascript
Anjan Banda
 
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
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 211 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
 
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 211 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
 
Ad

Recently uploaded (20)

PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Import Data Form Excel to Tally Services
Tally xperts
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 

The Ring programming language version 1.10 book - Part 17 of 212

  • 1. Ring Documentation, Release 1.10 Trace Function Name : mytrace() Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Function Line Number : 9 File Name : test1.ring Function Name : mymethod Method or Function : Method ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 44 File Name : test1.ring Function Name : mymethod Method or Function : Method ========================================== Message from mymethod ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Return Line Number : 9 File Name : test1.ring Function Name : Method or Function : Command ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() 9.14. Ring VM - Tracing Functions 128
  • 2. Ring Documentation, Release 1.10 Trace Event : Before C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : After C Function Line Number : 9 File Name : test1.ring Function Name : ismethod Method or Function : Function ========================================== ====== The Trace function is Active ====== Trace Function Name : mytrace() Trace Event : New Line Line Number : 11 File Name : test1.ring Function Name : Method or Function : Command ========================================== 9.15 Trace Library and Interactive Debugger Ring 1.5 comes with the Trace Library and the Interactive Debugger Using this library we can trace events, execute programs line by line, open the Interactive Debugger when an error happens or at breakpoints. Example: The next example uses a Breakpoint to open the Interactive Debugger! load "tracelib.ring" test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl Screen Shots: We have the Interactive Debugger at the Breakpoint! 9.15. Trace Library and Interactive Debugger 129
  • 3. Ring Documentation, Release 1.10 We can print the variables values We can change the variables values then continue execution We can run the Interactive Debugger in the Output Window 9.15. Trace Library and Interactive Debugger 130
  • 4. Ring Documentation, Release 1.10 9.16 More Syntax Flexibility • Using braces { } in Packages/Classes/Functions Example: load "stdlib.ring" import mypackage new myclass { myfunc() } package mypackage { class myclass { func myfunc { print("Hello, World!n") } } } • Using ‘end’ keyword after Packages/Classes/Functions Example: import mypackage new myclass { myfunc() } 9.16. More Syntax Flexibility 131
  • 5. Ring Documentation, Release 1.10 package mypackage class myclass def myfunc put "Hello, World!" end end end • Using ‘endpackage’/’endclass’/’endfunc’ keywords after Packages/Classes/Functions Example: import mypackage new myclass { myfunc() } package mypackage class myclass func myfunc see "welcome" + nl endfunc endclass endpackage 9.17 Type Hints Library Ring 1.5 comes with the Type Hints library Using this library we can add the type information to the source code which will be very useful for tools like • Code Editors • Static-Analysis Example: load "typehints.ring" see sum(3,4) + nl ; see sayHello("Mahmoud"); int func sum(int x,int y) { return x+y ; } string func sayHello(string name) { return "Hello " + name ; } The library is very powerful and support the User types (Classes) automatically! Example: load "typehints.ring" import mypackage test() { main([:one,:two,:three]) } 9.17. Type Hints Library 132
  • 6. Ring Documentation, Release 1.10 myclass func test() { see "Testing User Types!" + nl return new myclass } package mypackage { public class myclass { public static void func main(list args) { see "welcome" + nl see args } } } Also You can use the types inside the code (not only the function prototype) Example: load "typehints.ring" int sum = sum(3,4) string msg = sayHello("Mahmoud") see "Sum = " + sum + nl + msg + nl int func sum(int x,int y) { return x+y ; } string func sayHello(string name) { return "Hello " + name ; } Rules: • To use the types in the function prototype, You must use ‘(‘ and ‘)’ around parameters • To use the types in the function code, You must set the variable value (Assignment). Note: Ring is a dynamic language, No type checking will be done by the compiler. 9.18 Better Quality Based on Ring usage every day in practical projects Ring 1.5 is more stable and more productive! We are adding features based on clear vision and practical needs. Also the documentation is better. 9.19 What is new in Ring 1.5.1? • Better Documentation 9.18. Better Quality 133
  • 7. Ring Documentation, Release 1.10 • StdLib - Factorial() function update • RingVM - Better code for clearing the stack in the Class Region. • Sample : 3D Cube (OpenGL) + Texture Image using GameLib (RingAllegro) Source Code: load "gamelib.ring" load "opengl21lib.ring" func main new GraphicsApp { start() } class GraphicsApp from GraphicsAppBase TITLE = "Ring Cube" bitmap texture xrot = 0.0 yrot = 0.0 zrot = 0.0 func loadresources bitmap = al_load_bitmap("ring.bmp") texture = al_get_opengl_texture(bitmap) func destroyResources al_destroy_bitmap(bitmap) func drawScene w = 800 h = 600 ratio = w / h glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45,ratio,1,100) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable(GL_TEXTURE_2D) glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.0, 0.0, 0.5) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 9.19. What is new in Ring 1.5.1? 134
  • 8. Ring Documentation, Release 1.10 glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); glRotatef(xrot,1.0,0.0,0.0); glRotatef(yrot,0.0,1.0,0.0); glRotatef(zrot,0.0,0.0,1.0); glBindTexture(GL_TEXTURE_2D, texture) glBegin(GL_QUADS) // Front Face glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, 1.0) glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, 1.0) glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, 1.0) // Back Face glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, -1.0) glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, -1.0) glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, -1.0) glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, -1.0) // Top Face glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0) glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, 1.0, 1.0) glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, 1.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0) // Bottom Face glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, -1.0, -1.0) glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, -1.0, -1.0) glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0) glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0) // Right face glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, -1.0) glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0) glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, 1.0) glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0) // Left Face glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, -1.0) glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0) glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, 1.0) glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0) glEnd() xrot += 0.3 yrot += 0.2 zrot += 0.4 class GraphicsAppBase display event_queue ev timeout timer redraw = true FPS = 60 SCREEN_W = 800 SCREEN_H = 600 KEY_UP = 1 9.19. What is new in Ring 1.5.1? 135
  • 9. Ring Documentation, Release 1.10 KEY_DOWN = 2 KEY_LEFT = 3 KEY_RIGHT = 4 Key = [false,false,false,false] TITLE = "Graphics Application" func start SetUp() loadResources() eventsLoop() destroy() func setup al_init() al_init_image_addon() al_set_new_display_flags(ALLEGRO_OPENGL) display = al_create_display(SCREEN_W,SCREEN_H) al_set_Window_title(display,TITLE) al_clear_to_color(al_map_rgb(0,0,0)) event_queue = al_create_event_queue() al_register_event_source(event_queue, al_get_display_event_source(display)) ev = al_new_allegro_event() timeout = al_new_allegro_timeout() al_init_timeout(timeout, 0.06) timer = al_create_timer(1.0 / FPS) al_register_event_source(event_queue, al_get_timer_event_source(timer)) al_start_timer(timer) al_install_mouse() al_register_event_source(event_queue, al_get_mouse_event_source()) al_install_keyboard() al_register_event_source(event_queue, al_get_keyboard_event_source()) func eventsLoop while true al_wait_for_event_until(event_queue, ev, timeout) switch al_get_allegro_event_type(ev) on ALLEGRO_EVENT_DISPLAY_CLOSE exit on ALLEGRO_EVENT_TIMER redraw = true on ALLEGRO_EVENT_MOUSE_AXES mouse_x = al_get_allegro_event_mouse_x(ev) mouse_y = al_get_allegro_event_mouse_y(ev) on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY mouse_x = al_get_allegro_event_mouse_x(ev) mouse_y = al_get_allegro_event_mouse_y(ev) on ALLEGRO_EVENT_MOUSE_BUTTON_UP exit on ALLEGRO_EVENT_KEY_DOWN 9.19. What is new in Ring 1.5.1? 136
  • 10. Ring Documentation, Release 1.10 switch al_get_allegro_event_keyboard_keycode(ev) on ALLEGRO_KEY_UP key[KEY_UP] = true on ALLEGRO_KEY_DOWN key[KEY_DOWN] = true on ALLEGRO_KEY_LEFT key[KEY_LEFT] = true on ALLEGRO_KEY_RIGHT key[KEY_RIGHT] = true off on ALLEGRO_EVENT_KEY_UP switch al_get_allegro_event_keyboard_keycode(ev) on ALLEGRO_KEY_UP key[KEY_UP] = false on ALLEGRO_KEY_DOWN key[KEY_DOWN] = false on ALLEGRO_KEY_LEFT key[KEY_LEFT] = false on ALLEGRO_KEY_RIGHT key[KEY_RIGHT] = false on ALLEGRO_KEY_ESCAPE exit off off if redraw and al_is_event_queue_empty(event_queue) redraw = false drawScene() al_flip_display() ok callgc() end func destroy destroyResources() al_destroy_timer(timer) al_destroy_allegro_event(ev) al_destroy_allegro_timeout(timeout) al_destroy_event_queue(event_queue) al_destroy_display(display) func loadresources func drawScene func destroyResources Screen Shot: 9.19. What is new in Ring 1.5.1? 137