SlideShare a Scribd company logo
Ring Documentation, Release 1.7
y: 20.000000
z: 30.000000
70.27 ringvm_give() function
Using the ringvm_give() function we can redefine the behavior of the Give command
Example:
see "Name: " give name
see "Hello " + name
func ringvm_give
see "Mahmoud" + nl
return "Mahmoud"
Output:
Name: Mahmoud
Hello Mahmoud
70.27. ringvm_give() function 812
CHAPTER
SEVENTYONE
THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER
In this chapter we will learn about the Trace Library and the Interactive Debugger
71.1 Loading the Trace library
To start using the Trace library, We must load it first!
load "tracelib.ring"
71.2 Trace All Events
The next example demonstrates the Trace library usage to trace all events.
# Trace All Events
trace(:AllEvents)
see "Hello, world!" + nl
see "Welcome" + nl
see "How are you?" +nl
mytest()
new myclass { mymethod() }
func mytest
see "Message from mytest" + nl
class myclass
func mymethod
see "Message from mymethod" + nl
71.3 Trace control flow between functions
The next example demonstrates the Trace library usage to trace the control flow between functions.
Trace(:Functions)
test1()
813
Ring Documentation, Release 1.7
func test1
see :test1 + nl
test2()
func test2
see :test2 + nl
see test3() + nl
func test3
see :test3 + nl
return "test 3 output"
71.4 Pass Error
The next example demonstrates the Trace library usage to pass an error!
Trace(:PassError)
test1()
func test1
x = 10
see :test1 + nl
test2() # Runtime Error!
see "We can continue!"
71.5 Interactive Debugger
The next example demonstrates the Trace library usage to use the Interactive Debugger
Trace(:Debugger)
test1()
see "good bye!" + nl
func test1
x = 10
see :test1 + nl
t = 12
test2() # Runtime Error!
see "After Error!" +nl
see "t = " see t see nl
see "x = " see x see nl
71.6 Execute Program Line by Line
The next example demonstrates the Trace library usage to execute the program line by line!
Trace(:LineByLine)
test1()
71.4. Pass Error 814
Ring Documentation, Release 1.7
func test1
x = 10
see :test1 + nl
t = 12
test2()
see "After Error!" +nl
see "t = " + t + nl
71.7 BreakPoint
The next example demonstrates the Trace library usage to stop at a breakpoint!
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
71.8 Disable BreakPoints
The next example demonstrates the Trace library usage and how to disable the Breakpoints!
NoBreakPoints()
test1()
func test1
x = 10
see :test1 + nl
t = 12
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
71.9 Using the Interactive Debugger
The next example uses a Breakpoint to open the Interactive Debugger!
load "tracelib.ring"
test1()
func test1
x = 10
see :test1 + nl
t = 12
71.7. BreakPoint 815
Ring Documentation, Release 1.7
BreakPoint()
see "After breakpoint!" +nl
see "t = " + t + nl
see "End of program!" + nl
Screen Shots:
We have the Interactive Debugger at the Breakpoint!
We can print the variables values
We can change the variables values then continue execution
71.9. Using the Interactive Debugger 816
Ring Documentation, Release 1.7
We can run the Interactive Debugger in the Output Window
71.9. Using the Interactive Debugger 817
CHAPTER
SEVENTYTWO
EMBEDDING RING IN RING
In this chapter we will learn about embedding Ring in Ring programs and applications.
72.1 Embedding Ring in Ring without sharing the State
From Ring 1.0 we already have functions for embedding Ring in the C language. Also we can execute Ring code
inside Ring programs using the eval() function. In this release we provide functions for embedding Ring in Ring
programs without sharing the state.
Advantages:
1. Quick integration for Ring programs and applications together without conflicts.
2. Execute and run Ring code in safe environments that we can trace.
Example:
pState = ring_state_init()
ring_state_runcode(pState,"See 'Hello, World!'+nl")
ring_state_runcode(pState,"x = 10")
pState2 = ring_state_init()
ring_state_runcode(pState2,"See 'Hello, World!'+nl")
ring_state_runcode(pState2,"x = 20")
ring_state_runcode(pState,"see x +nl")
ring_state_runcode(pState2,"see x +nl")
v1 = ring_state_findvar(pState,"x")
v2 = ring_state_findvar(pState2,"x")
see v1[3] + nl
see V2[3] + nl
ring_state_delete(pState)
ring_state_delete(pState2)
Output:
Hello, World!
Hello, World!
10
20
10
20
818
Ring Documentation, Release 1.7
72.2 Serial Execution of Programs
We can execute application after another application using ring_state_main()
Example:
chdir(exefolder()+"/../applications/formdesigner")
ring_state_main('formdesigner.ring')
chdir(exefolder()+"/../applications/cards")
ring_state_main('cards.ring')
72.3 ring_state_setvar()
Using ring_state_setvar() we can set variables value
The value could be (String, Number, List or C Pointer)
We need this function to quickly pass lists and C pointers to the Sub Ring Environment
Syntax:
ring_state_setvar(oState,cVariableName,Value)
Example:
load "guilib.ring"
myapp = null
win = null
func main
myapp = new qApp {
win = new qWidget() {
setWindowTitle("Advanced Example on using ring_state_setvar()")
move(100,100)
resize(600,400)
new qPushButton(win) {
setText("Test")
setClickEvent("Test()")
}
# We need this because using load 'guilib.ring' in the sub environment
# Will create timers by Qt and closing the window will not be enough
# To close the application
oFilter = new qAllEvents(win)
oFilter.setCloseEvent("myapp.quit()")
win.installeventfilter(oFilter)
show()
}
exec()
}
func test
pState = ring_state_init()
ring_state_runcode(pstate,"load 'guilib.ring'")
ring_state_runcode(pState,"x = NULL")
# Pass String
ring_state_setvar(pState,"x","hello")
72.2. Serial Execution of Programs 819
Ring Documentation, Release 1.7
ring_state_runcode(pState,"? x")
# Pass Number
ring_state_setvar(pState,"x",100)
ring_state_runcode(pState,"? x")
# Pass List
ring_state_setvar(pState,"x",["one","two","three"])
ring_state_runcode(pState,"? x")
# Pass Object
# We can't pass the Ring Object (win)
# Because Objects store pointers to the Class Information
# And the class is related to the Parent Ring Environment
# And the sub Ring environment can't access it
# But we can pass C pointers like win.pObject
ring_state_setvar(pState,"x",win.pObject)
# Now we create the object again but using the same C pointer
# So we have access to the Same window in the parent Ring enviroment
ring_state_runcode(pState,"
new qWidget {
pObject = x
setwindowtitle('Message from the Sub Ring Environment')
}
")
ring_state_delete(pState)
72.4 ring_state_new() and ring_state_mainfile()
Using ring_state_new() and ring_state_mainfile() we can run Ring programs from Ring programs
But unlike ring_state_main(), Here we can control when to delete the Ring state!
This is important when we run GUI programs from GUI programs
Because they will share the GUI Library (RingQt), And In this case the caller will call
qApp.Exec()
So the sub program, will not stop and will return to the Main program
Here deleting the State of the sub programs will lead to a problem when we run the sub program events
So keeping the state is important for sub GUI programs hosted in GUI programs.
Example:
load "guilib.ring"
func main
new qApp {
win = new qWidget() {
setWindowTitle("Test ring_state_mainfile()")
resize(400,400) move(100,100)
btn = new qPushButton(Win) {
settext("test")
setclickevent("mytest()")
}
show()
}
exec()
}
72.4. ring_state_new() and ring_state_mainfile() 820
Ring Documentation, Release 1.7
func mytest
pState = ring_state_new()
ring_state_mainfile(pState,"runprogram.ring")
# Here we don't delete the state if we will run GUI application
# So we can run the GUI application events
// ring_state_delete(pState)
If you will use this feature, remember to update the previous example based on your application needs
So you can call ring_state_delete() at some point to avoid the memory leak!
72.4. ring_state_new() and ring_state_mainfile() 821

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.5.1 book - Part 74 of 180
Mahmoud Samir Fayed
 
PPTX
Rxjs ppt
Christoffer Noring
 
PPTX
Theorical 1
everblut
 
PDF
Primi passi con Project Tango
Michelantonio Trizio
 
PPTX
Fine grain process control 2nd nov
SurendraGangarapu1
 
PPS
Unbounded
Ever Blut
 
PPT
Unbounded
Ever Blut
 
PPTX
Teorical 1
everblut
 
PDF
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
PPTX
From clever code to better code
Dror Helper
 
PDF
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
Sylvain Hallé
 
PDF
Java Practical File Diploma
mustkeem khan
 
PPT
Swiss army knife Spring
Mario Fusco
 
PDF
React new features and intro to Hooks
Soluto
 
PDF
Spring Transaction
Jannarong Wadthong
 
PDF
React hooks beyond hype
Magdiel Duarte
 
PPTX
Java Script Promise
Alok Guha
 
PDF
The Ring programming language version 1.8 book - Part 86 of 202
Mahmoud Samir Fayed
 
PDF
Think Async: Asynchronous Patterns in NodeJS
Adam L Barrett
 
The Ring programming language version 1.5.1 book - Part 74 of 180
Mahmoud Samir Fayed
 
Theorical 1
everblut
 
Primi passi con Project Tango
Michelantonio Trizio
 
Fine grain process control 2nd nov
SurendraGangarapu1
 
Unbounded
Ever Blut
 
Unbounded
Ever Blut
 
Teorical 1
everblut
 
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
From clever code to better code
Dror Helper
 
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
Sylvain Hallé
 
Java Practical File Diploma
mustkeem khan
 
Swiss army knife Spring
Mario Fusco
 
React new features and intro to Hooks
Soluto
 
Spring Transaction
Jannarong Wadthong
 
React hooks beyond hype
Magdiel Duarte
 
Java Script Promise
Alok Guha
 
The Ring programming language version 1.8 book - Part 86 of 202
Mahmoud Samir Fayed
 
Think Async: Asynchronous Patterns in NodeJS
Adam L Barrett
 

Similar to The Ring programming language version 1.7 book - Part 85 of 196 (20)

PDF
The Ring programming language version 1.5.3 book - Part 89 of 184
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.5.1 book - Part 12 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 7 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 83 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 41 of 189
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.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 13 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 21 of 212
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.7 book - Part 92 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 95 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 12 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 102 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 85 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 20 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 7 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.9 book - Part 92 of 210
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.7 book - Part 7 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 7 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 83 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 41 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 7 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 13 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 21 of 212
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.7 book - Part 92 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 95 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 12 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 102 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 85 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 20 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 7 of 202
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
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

The Ring programming language version 1.7 book - Part 85 of 196

  • 1. Ring Documentation, Release 1.7 y: 20.000000 z: 30.000000 70.27 ringvm_give() function Using the ringvm_give() function we can redefine the behavior of the Give command Example: see "Name: " give name see "Hello " + name func ringvm_give see "Mahmoud" + nl return "Mahmoud" Output: Name: Mahmoud Hello Mahmoud 70.27. ringvm_give() function 812
  • 2. CHAPTER SEVENTYONE THE TRACE LIBRARY AND THE INTERACTIVE DEBUGGER In this chapter we will learn about the Trace Library and the Interactive Debugger 71.1 Loading the Trace library To start using the Trace library, We must load it first! load "tracelib.ring" 71.2 Trace All Events The next example demonstrates the Trace library usage to trace all events. # Trace All Events trace(:AllEvents) see "Hello, world!" + nl see "Welcome" + nl see "How are you?" +nl mytest() new myclass { mymethod() } func mytest see "Message from mytest" + nl class myclass func mymethod see "Message from mymethod" + nl 71.3 Trace control flow between functions The next example demonstrates the Trace library usage to trace the control flow between functions. Trace(:Functions) test1() 813
  • 3. Ring Documentation, Release 1.7 func test1 see :test1 + nl test2() func test2 see :test2 + nl see test3() + nl func test3 see :test3 + nl return "test 3 output" 71.4 Pass Error The next example demonstrates the Trace library usage to pass an error! Trace(:PassError) test1() func test1 x = 10 see :test1 + nl test2() # Runtime Error! see "We can continue!" 71.5 Interactive Debugger The next example demonstrates the Trace library usage to use the Interactive Debugger Trace(:Debugger) test1() see "good bye!" + nl func test1 x = 10 see :test1 + nl t = 12 test2() # Runtime Error! see "After Error!" +nl see "t = " see t see nl see "x = " see x see nl 71.6 Execute Program Line by Line The next example demonstrates the Trace library usage to execute the program line by line! Trace(:LineByLine) test1() 71.4. Pass Error 814
  • 4. Ring Documentation, Release 1.7 func test1 x = 10 see :test1 + nl t = 12 test2() see "After Error!" +nl see "t = " + t + nl 71.7 BreakPoint The next example demonstrates the Trace library usage to stop at a breakpoint! test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 71.8 Disable BreakPoints The next example demonstrates the Trace library usage and how to disable the Breakpoints! NoBreakPoints() test1() func test1 x = 10 see :test1 + nl t = 12 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl 71.9 Using the Interactive Debugger The next example uses a Breakpoint to open the Interactive Debugger! load "tracelib.ring" test1() func test1 x = 10 see :test1 + nl t = 12 71.7. BreakPoint 815
  • 5. Ring Documentation, Release 1.7 BreakPoint() see "After breakpoint!" +nl see "t = " + t + nl see "End of program!" + nl Screen Shots: We have the Interactive Debugger at the Breakpoint! We can print the variables values We can change the variables values then continue execution 71.9. Using the Interactive Debugger 816
  • 6. Ring Documentation, Release 1.7 We can run the Interactive Debugger in the Output Window 71.9. Using the Interactive Debugger 817
  • 7. CHAPTER SEVENTYTWO EMBEDDING RING IN RING In this chapter we will learn about embedding Ring in Ring programs and applications. 72.1 Embedding Ring in Ring without sharing the State From Ring 1.0 we already have functions for embedding Ring in the C language. Also we can execute Ring code inside Ring programs using the eval() function. In this release we provide functions for embedding Ring in Ring programs without sharing the state. Advantages: 1. Quick integration for Ring programs and applications together without conflicts. 2. Execute and run Ring code in safe environments that we can trace. Example: pState = ring_state_init() ring_state_runcode(pState,"See 'Hello, World!'+nl") ring_state_runcode(pState,"x = 10") pState2 = ring_state_init() ring_state_runcode(pState2,"See 'Hello, World!'+nl") ring_state_runcode(pState2,"x = 20") ring_state_runcode(pState,"see x +nl") ring_state_runcode(pState2,"see x +nl") v1 = ring_state_findvar(pState,"x") v2 = ring_state_findvar(pState2,"x") see v1[3] + nl see V2[3] + nl ring_state_delete(pState) ring_state_delete(pState2) Output: Hello, World! Hello, World! 10 20 10 20 818
  • 8. Ring Documentation, Release 1.7 72.2 Serial Execution of Programs We can execute application after another application using ring_state_main() Example: chdir(exefolder()+"/../applications/formdesigner") ring_state_main('formdesigner.ring') chdir(exefolder()+"/../applications/cards") ring_state_main('cards.ring') 72.3 ring_state_setvar() Using ring_state_setvar() we can set variables value The value could be (String, Number, List or C Pointer) We need this function to quickly pass lists and C pointers to the Sub Ring Environment Syntax: ring_state_setvar(oState,cVariableName,Value) Example: load "guilib.ring" myapp = null win = null func main myapp = new qApp { win = new qWidget() { setWindowTitle("Advanced Example on using ring_state_setvar()") move(100,100) resize(600,400) new qPushButton(win) { setText("Test") setClickEvent("Test()") } # We need this because using load 'guilib.ring' in the sub environment # Will create timers by Qt and closing the window will not be enough # To close the application oFilter = new qAllEvents(win) oFilter.setCloseEvent("myapp.quit()") win.installeventfilter(oFilter) show() } exec() } func test pState = ring_state_init() ring_state_runcode(pstate,"load 'guilib.ring'") ring_state_runcode(pState,"x = NULL") # Pass String ring_state_setvar(pState,"x","hello") 72.2. Serial Execution of Programs 819
  • 9. Ring Documentation, Release 1.7 ring_state_runcode(pState,"? x") # Pass Number ring_state_setvar(pState,"x",100) ring_state_runcode(pState,"? x") # Pass List ring_state_setvar(pState,"x",["one","two","three"]) ring_state_runcode(pState,"? x") # Pass Object # We can't pass the Ring Object (win) # Because Objects store pointers to the Class Information # And the class is related to the Parent Ring Environment # And the sub Ring environment can't access it # But we can pass C pointers like win.pObject ring_state_setvar(pState,"x",win.pObject) # Now we create the object again but using the same C pointer # So we have access to the Same window in the parent Ring enviroment ring_state_runcode(pState," new qWidget { pObject = x setwindowtitle('Message from the Sub Ring Environment') } ") ring_state_delete(pState) 72.4 ring_state_new() and ring_state_mainfile() Using ring_state_new() and ring_state_mainfile() we can run Ring programs from Ring programs But unlike ring_state_main(), Here we can control when to delete the Ring state! This is important when we run GUI programs from GUI programs Because they will share the GUI Library (RingQt), And In this case the caller will call qApp.Exec() So the sub program, will not stop and will return to the Main program Here deleting the State of the sub programs will lead to a problem when we run the sub program events So keeping the state is important for sub GUI programs hosted in GUI programs. Example: load "guilib.ring" func main new qApp { win = new qWidget() { setWindowTitle("Test ring_state_mainfile()") resize(400,400) move(100,100) btn = new qPushButton(Win) { settext("test") setclickevent("mytest()") } show() } exec() } 72.4. ring_state_new() and ring_state_mainfile() 820
  • 10. Ring Documentation, Release 1.7 func mytest pState = ring_state_new() ring_state_mainfile(pState,"runprogram.ring") # Here we don't delete the state if we will run GUI application # So we can run the GUI application events // ring_state_delete(pState) If you will use this feature, remember to update the previous example based on your application needs So you can call ring_state_delete() at some point to avoid the memory leak! 72.4. ring_state_new() and ring_state_mainfile() 821