You are on page 1of 10

Ring Documentation, Release 1.

GLUT_BITMAP_HELVETICA_18
</constant>

5.13 Better Documentation Generator for Extensions

The documentation generator for extensions is updated to generate a list of constants in the generated documentation
The previous versions provides the functions prototype only, Now we have the list of constants too.

5.14 Ring VM - Tracing Functions

In Ring 1.5 the next functions are added to Ring VM


• RingVM_SetTrace(cCode)
• RingVM_TraceData() –> aDataList
• RingVM_TraceEvent() –> nTraceEvent
• RingVM_TraceFunc() –> cCode
• RingVM_ScopesCount() –> nScopes
• RingVM_EvalInScope(nScope,cCode)
• RingVM_PassError()
• RingVM_HideErrorMsg(lStatus)
• RingVM_CallFunc(cFuncName)
Example:
load "tracelib.ring"

ringvm_settrace("mytrace()")

see "Hello, world!" + nl


see "Welcome" + nl
see "How are you?" +nl
mytest()
new myclass { mymethod() }

func mytest
see "Message from mytest" + nl

func mytrace
see "====== The Trace function is Active ======" + nl +
"Trace Function Name : " + ringvm_TraceFunc() + nl +
"Trace Event : "
switch ringvm_TraceEvent()
on TRACEEVENT_NEWLINE see "New Line"
on TRACEEVENT_NEWFUNC see "New Function"
on TRACEEVENT_RETURN see "Return"
on TRACEEVENT_ERROR see "Error"
on TRACEEVENT_BEFORECFUNC see "Before C Function"
on TRACEEVENT_AFTERCFUNC see "After C Function"
off

5.13. Better Documentation Generator for Extensions 73


Ring Documentation, Release 1.6

see nl +
"Line Number : " + ringvm_tracedata()[TRACEDATA_LINENUMBER] + nl +
"File Name : " + ringvm_tracedata()[TRACEDATA_FILENAME] + nl +
"Function Name : " + ringvm_tracedata()[TRACEDATA_FUNCNAME] + nl +
"Method or Function : "
if ringvm_tracedata()[TRACEDATA_METHODORFUNC] =
TRACEDATA_METHODORFUNC_METHOD
see "Method"
else
if ringvm_tracedata()[TRACEDATA_FUNCNAME] = NULL
see "Command"
else
see "Function"
ok
ok
see nl + Copy("=",42) + nl

class myclass
func mymethod
see "Message from mymethod" + nl

Output:
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : After C Function
Line Number : 3
File Name : test1.ring
Function Name : ringvm_settrace
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 5
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
Hello, world!
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 6
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
Welcome
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 7
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
How are you?

5.14. Ring VM - Tracing Functions 74


Ring Documentation, Release 1.6

====== The Trace function is Active ======


Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 8
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Function
Line Number : 8
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 12
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
Message from mytest
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 14
File Name : test1.ring
Function Name : mytest
Method or Function : Function
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : Return
Line Number : 8
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 9
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======
Trace Function Name : mytrace()
Trace Event : New Line
Line Number : 43
File Name : test1.ring
Function Name :
Method or Function : Command
==========================================
====== The Trace function is Active ======

5.14. Ring VM - Tracing Functions 75


Ring Documentation, Release 1.6

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()

5.14. Ring VM - Tracing Functions 76


Ring Documentation, Release 1.6

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
==========================================

5.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!

5.15. Trace Library and Interactive Debugger 77


Ring Documentation, Release 1.6

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

5.15. Trace Library and Interactive Debugger 78


Ring Documentation, Release 1.6

5.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()
}

5.16. More Syntax Flexibility 79


Ring Documentation, Release 1.6

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

5.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]) }

5.17. Type Hints Library 80


Ring Documentation, Release 1.6

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.

5.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.

5.19 What is new in Ring 1.5.1?

• Better Documentation

5.18. Better Quality 81


Ring Documentation, Release 1.6

• 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)

5.19. What is new in Ring 1.5.1? 82

You might also like