SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
CHAPTER
SEVENTY
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()
• ringvm_see()
• ringvm_give()
792
Ring Documentation, Release 1.7
70.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.
70.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)
70.3 space() function
Use the space function to allocate a specific number of bytes in Memory.
70.1. callgc() function 793
Ring Documentation, Release 1.7
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.
70.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()
70.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 )
70.6 pointer2object() function
Use this function to get the Ring list and/or object from the low level object (C Pointer)
70.4. nullpointer() function 794
Ring Documentation, Release 1.7
Syntax:
pointer2object(Low Level Object) ---> List|Object
Example:
# Create the list
mylist = 1:5
# Create pointer to the list
x = object2pointer(mylist)
see x
see nl
# Add items to the list
mylist + "welcome"
# print the list items
y = pointer2object(x)
see y
Output:
0069A5D8
OBJECTPOINTER
0
1
2
3
4
5
welcome
Note: In Ring the assignment operator copy lists and objects by value, to copy by reference Just use the ob-
ject2pointer() and pointer2object() functions.
Tip: The object2pointer() and pointer2object() are used in the stdlib - Tree Class implementation to create a reference
for the parent node (object) in the child node (another object).
70.7 ptrcmp() function
We can compare between two pointers (C Objects) using the ptrcmp() function.
Syntax:
ptrcmp(oObject1,oObject2) ---> value = 1 if oObject1 = oObject2
value = 0 if oObject1 != oObject2
Example:
fp = fopen("ptrcmp.ring","r")
fp2 = fp
fp3 = fopen("ptrcmp.ring","r")
70.7. ptrcmp() function 795
Ring Documentation, Release 1.7
see ptrcmp(fp,fp2) + nl
see ptrcmp(fp,fp3) + nl
fclose(fp)
fclose(fp3)
Output:
1
0
70.8 ringvm_cfunctionslist() function
The Function return a list of functions written in C.
Syntax:
RingVM_CFunctionsList() ---> List
Example:
See RingVM_CFunctionsList()
70.9 ringvm_functionslist() function
The Function return a list of functions written in Ring.
Each List Member is a list contains the next items
• Function Name
• Program Counter (PC) - Function Position in Byte Code.
• Source Code File Name
• Private Flag (For Private Methods in Classes)
Syntax:
RingVM_FunctionsList() ---> List
Example:
test()
func test
see ringvm_functionslist()
Output:
test
8
B:/ring/tests/scripts/functionslist.ring
0
70.8. ringvm_cfunctionslist() function 796
Ring Documentation, Release 1.7
70.10 ringvm_classeslist() function
The Function return a list of Classes.
Each List Member is a list contains the next items
• Class Name
• Program Counter (PC) - Class Position in Byte Code.
• Parent Class Name
• Methods List
• Flag (Is parent class information collected)
• Pointer to the package (or NULL if no package is used)
Syntax:
RingVM_ClassesList() ---> List
Example:
see ringvm_classeslist()
class class1
func f1
class class2 from class1
class class3 from class1
Output:
class1
9
f1
13
B:/ring/tests/scripts/classeslist.ring
0
0
00000000
class2
16
class1
0
00000000
class3
20
class1
0
00000000
70.11 ringvm_packageslist() function
The Function return a list of Packages.
Each List Member is a list contains the next items
• Package Name
70.10. ringvm_classeslist() function 797
Ring Documentation, Release 1.7
• Classes List
Syntax:
RingVM_PackagesList() ---> List
Example:
see ringvm_packageslist()
package package1
class class1
package package2
class class1
package package3
class class1
Output:
package1
class1
11
0
00FEF838
package2
class1
17
0
00FEF978
package3
class1
23
0
00FEFF68
70.12 ringvm_memorylist() function
The Function return a list of Memory Scopes and Variables.
Each List Member is a list contains variables in a different scope.
Each Item in the scope list is a list contains the next items
• Variable Name
• Variable Type
• Variable Value
• Pointer Type (List/Item) if the value is a list
• Private Flag (if the variable is an attribute in a Class)
Syntax:
70.12. ringvm_memorylist() function 798
Ring Documentation, Release 1.7
RingVM_MemoryList() ---> List
Example:
x = 10
test()
func test
y = 20
see ringvm_memorylist()
Output:
true
2
1
0
0
false
2
0
0
0
nl
1
0
0
null
1
0
0
ring_gettemp_var
4
00000000
0
0
ccatcherror
1
NULL
0
0
ring_settemp_var
4
00000000
0
0
ring_tempflag_var
2
0
0
0
stdin
3
50512DB8
file
0
0
70.12. ringvm_memorylist() function 799
Ring Documentation, Release 1.7
0
stdout
3
50512DD8
file
0
0
0
stderr
3
50512DF8
file
0
0
0
this
4
00000000
0
0
sysargv
3
B:ringbin/ring
B:/ring/tests/scripts/memorylist.ring
0
0
x
2
10
0
0
y
2
20
0
0
70.13 ringvm_calllist() function
The Function return a list of the functions call list.
Each List Member is a list contains the next items
• Function Type
• Function Name
• Program Counter (PC)
• Stack Pointer (SP)
• Temp. Memory List
• Method or Function Flag
• Caller PC
• FuncExec Flag
• ListStart Flag
70.13. ringvm_calllist() function 800
Ring Documentation, Release 1.7
• Nested Lists Pointer
• State List
Syntax:
RingVM_CallList() ---> List
Example:
hello()
func hello
test()
func test
mylist = ringvm_calllist()
for t in mylist see t[2] + nl next
Output:
function hello() in file B:/ring/tests/scripts/calllist.ring
called from line 1
function test() in file B:/ring/tests/scripts/calllist.ring
called from line 3
ringvm_calllist
70.14 ringvm_fileslist() function
Function return a list of the Ring Files.
Syntax:
RingVM_FilesList() ---> List
Example:
load "stdlib.ring"
see ringvm_fileslist()
Output:
B:/ring/tests/scripts/fileslist.ring
B:ringbinstdlib.ring
eval
stdlib.ring
stdlib.rh
stdclasses.ring
stdfunctions.ring
stdbase.ring
stdstring.ring
stdlist.ring
stdstack.ring
stdqueue.ring
stdmath.ring
stddatetime.ring
stdfile.ring
stdsystem.ring
stddebug.ring
stddatatype.ring
70.14. ringvm_fileslist() function 801

Más contenido relacionado

La actualidad más candente

User defined functions
User defined functionsUser defined functions
User defined functions
shubham_jangid
 
Lecture05 operator overloading-and_exception_handling
Lecture05 operator overloading-and_exception_handlingLecture05 operator overloading-and_exception_handling
Lecture05 operator overloading-and_exception_handling
Hariz Mustafa
 

La actualidad más candente (20)

Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189
 
Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”Bartosz Milewski, “Re-discovering Monads in C++”
Bartosz Milewski, “Re-discovering Monads in C++”
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180
 
Lecture05 operator overloading-and_exception_handling
Lecture05 operator overloading-and_exception_handlingLecture05 operator overloading-and_exception_handling
Lecture05 operator overloading-and_exception_handling
 
Python 如何執行
Python 如何執行Python 如何執行
Python 如何執行
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
 
V8
V8V8
V8
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
 
Day 1
Day 1Day 1
Day 1
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
The Ring programming language version 1.9 book - Part 123 of 210
The Ring programming language version 1.9 book - Part 123 of 210The Ring programming language version 1.9 book - Part 123 of 210
The Ring programming language version 1.9 book - Part 123 of 210
 

Similar a The Ring programming language version 1.7 book - Part 83 of 196

Similar a The Ring programming language version 1.7 book - Part 83 of 196 (20)

The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184
 
The Ring programming language version 1.9 book - Part 90 of 210
The Ring programming language version 1.9 book - Part 90 of 210The Ring programming language version 1.9 book - Part 90 of 210
The Ring programming language version 1.9 book - Part 90 of 210
 
The Ring programming language version 1.2 book - Part 57 of 84
The Ring programming language version 1.2 book - Part 57 of 84The Ring programming language version 1.2 book - Part 57 of 84
The Ring programming language version 1.2 book - Part 57 of 84
 
The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.5.2 book - Part 13 of 181The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.5.2 book - Part 13 of 181
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30
 
The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31
 
The Ring programming language version 1.5.4 book - Part 81 of 185
The Ring programming language version 1.5.4 book - Part 81 of 185The Ring programming language version 1.5.4 book - Part 81 of 185
The Ring programming language version 1.5.4 book - Part 81 of 185
 
Advance python
Advance pythonAdvance python
Advance python
 
The Ring programming language version 1.3 book - Part 6 of 88
The Ring programming language version 1.3 book - Part 6 of 88The Ring programming language version 1.3 book - Part 6 of 88
The Ring programming language version 1.3 book - Part 6 of 88
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180
 
The Ring programming language version 1.5.3 book - Part 14 of 184
The Ring programming language version 1.5.3 book - Part 14 of 184The Ring programming language version 1.5.3 book - Part 14 of 184
The Ring programming language version 1.5.3 book - Part 14 of 184
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
The Ring programming language version 1.5.2 book - Part 75 of 181
The Ring programming language version 1.5.2 book - Part 75 of 181The Ring programming language version 1.5.2 book - Part 75 of 181
The Ring programming language version 1.5.2 book - Part 75 of 181
 
The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185The Ring programming language version 1.5.4 book - Part 77 of 185
The Ring programming language version 1.5.4 book - Part 77 of 185
 
Lecture5
Lecture5Lecture5
Lecture5
 
The Ring programming language version 1.8 book - Part 18 of 202
The Ring programming language version 1.8 book - Part 18 of 202The Ring programming language version 1.8 book - Part 18 of 202
The Ring programming language version 1.8 book - Part 18 of 202
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202
 

Más de Mahmoud Samir Fayed

Más de Mahmoud Samir Fayed (20)

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

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

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

  • 1. CHAPTER SEVENTY 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() • ringvm_see() • ringvm_give() 792
  • 2. Ring Documentation, Release 1.7 70.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. 70.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) 70.3 space() function Use the space function to allocate a specific number of bytes in Memory. 70.1. callgc() function 793
  • 3. Ring Documentation, Release 1.7 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. 70.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() 70.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 ) 70.6 pointer2object() function Use this function to get the Ring list and/or object from the low level object (C Pointer) 70.4. nullpointer() function 794
  • 4. Ring Documentation, Release 1.7 Syntax: pointer2object(Low Level Object) ---> List|Object Example: # Create the list mylist = 1:5 # Create pointer to the list x = object2pointer(mylist) see x see nl # Add items to the list mylist + "welcome" # print the list items y = pointer2object(x) see y Output: 0069A5D8 OBJECTPOINTER 0 1 2 3 4 5 welcome Note: In Ring the assignment operator copy lists and objects by value, to copy by reference Just use the ob- ject2pointer() and pointer2object() functions. Tip: The object2pointer() and pointer2object() are used in the stdlib - Tree Class implementation to create a reference for the parent node (object) in the child node (another object). 70.7 ptrcmp() function We can compare between two pointers (C Objects) using the ptrcmp() function. Syntax: ptrcmp(oObject1,oObject2) ---> value = 1 if oObject1 = oObject2 value = 0 if oObject1 != oObject2 Example: fp = fopen("ptrcmp.ring","r") fp2 = fp fp3 = fopen("ptrcmp.ring","r") 70.7. ptrcmp() function 795
  • 5. Ring Documentation, Release 1.7 see ptrcmp(fp,fp2) + nl see ptrcmp(fp,fp3) + nl fclose(fp) fclose(fp3) Output: 1 0 70.8 ringvm_cfunctionslist() function The Function return a list of functions written in C. Syntax: RingVM_CFunctionsList() ---> List Example: See RingVM_CFunctionsList() 70.9 ringvm_functionslist() function The Function return a list of functions written in Ring. Each List Member is a list contains the next items • Function Name • Program Counter (PC) - Function Position in Byte Code. • Source Code File Name • Private Flag (For Private Methods in Classes) Syntax: RingVM_FunctionsList() ---> List Example: test() func test see ringvm_functionslist() Output: test 8 B:/ring/tests/scripts/functionslist.ring 0 70.8. ringvm_cfunctionslist() function 796
  • 6. Ring Documentation, Release 1.7 70.10 ringvm_classeslist() function The Function return a list of Classes. Each List Member is a list contains the next items • Class Name • Program Counter (PC) - Class Position in Byte Code. • Parent Class Name • Methods List • Flag (Is parent class information collected) • Pointer to the package (or NULL if no package is used) Syntax: RingVM_ClassesList() ---> List Example: see ringvm_classeslist() class class1 func f1 class class2 from class1 class class3 from class1 Output: class1 9 f1 13 B:/ring/tests/scripts/classeslist.ring 0 0 00000000 class2 16 class1 0 00000000 class3 20 class1 0 00000000 70.11 ringvm_packageslist() function The Function return a list of Packages. Each List Member is a list contains the next items • Package Name 70.10. ringvm_classeslist() function 797
  • 7. Ring Documentation, Release 1.7 • Classes List Syntax: RingVM_PackagesList() ---> List Example: see ringvm_packageslist() package package1 class class1 package package2 class class1 package package3 class class1 Output: package1 class1 11 0 00FEF838 package2 class1 17 0 00FEF978 package3 class1 23 0 00FEFF68 70.12 ringvm_memorylist() function The Function return a list of Memory Scopes and Variables. Each List Member is a list contains variables in a different scope. Each Item in the scope list is a list contains the next items • Variable Name • Variable Type • Variable Value • Pointer Type (List/Item) if the value is a list • Private Flag (if the variable is an attribute in a Class) Syntax: 70.12. ringvm_memorylist() function 798
  • 8. Ring Documentation, Release 1.7 RingVM_MemoryList() ---> List Example: x = 10 test() func test y = 20 see ringvm_memorylist() Output: true 2 1 0 0 false 2 0 0 0 nl 1 0 0 null 1 0 0 ring_gettemp_var 4 00000000 0 0 ccatcherror 1 NULL 0 0 ring_settemp_var 4 00000000 0 0 ring_tempflag_var 2 0 0 0 stdin 3 50512DB8 file 0 0 70.12. ringvm_memorylist() function 799
  • 9. Ring Documentation, Release 1.7 0 stdout 3 50512DD8 file 0 0 0 stderr 3 50512DF8 file 0 0 0 this 4 00000000 0 0 sysargv 3 B:ringbin/ring B:/ring/tests/scripts/memorylist.ring 0 0 x 2 10 0 0 y 2 20 0 0 70.13 ringvm_calllist() function The Function return a list of the functions call list. Each List Member is a list contains the next items • Function Type • Function Name • Program Counter (PC) • Stack Pointer (SP) • Temp. Memory List • Method or Function Flag • Caller PC • FuncExec Flag • ListStart Flag 70.13. ringvm_calllist() function 800
  • 10. Ring Documentation, Release 1.7 • Nested Lists Pointer • State List Syntax: RingVM_CallList() ---> List Example: hello() func hello test() func test mylist = ringvm_calllist() for t in mylist see t[2] + nl next Output: function hello() in file B:/ring/tests/scripts/calllist.ring called from line 1 function test() in file B:/ring/tests/scripts/calllist.ring called from line 3 ringvm_calllist 70.14 ringvm_fileslist() function Function return a list of the Ring Files. Syntax: RingVM_FilesList() ---> List Example: load "stdlib.ring" see ringvm_fileslist() Output: B:/ring/tests/scripts/fileslist.ring B:ringbinstdlib.ring eval stdlib.ring stdlib.rh stdclasses.ring stdfunctions.ring stdbase.ring stdstring.ring stdlist.ring stdstack.ring stdqueue.ring stdmath.ring stddatetime.ring stdfile.ring stdsystem.ring stddebug.ring stddatatype.ring 70.14. ringvm_fileslist() function 801