OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / whatisnew7.txt
1 .. index:: 
2         single: What is new in Ring 1.7?; Introduction
3
4 ========================
5 What is new in Ring 1.7?
6 ========================
7
8 In this chapter we will learn about the changes and new features in Ring 1.7 release.
9
10 .. index:: 
11         pair: What is new in Ring 1.7?; List of changes and new features
12
13 List of changes and new features
14 ================================
15
16 Ring 1.7 comes with many new features!
17
18 * New Command: Load Package
19 * ringvm_see() and ringvm_give() functions
20 * ring_state_new() and ring_state_mainfile() functions
21 * Better Trace Library
22 * Better Ring Notepad
23 * Better RingQt
24 * Better Ring2EXE
25 * Better RingZip
26 * Better Documentation
27 * Better Ring VM
28 * RingLibuv Extension
29
30
31 .. index:: 
32         pair: What is new in Ring 1.7?; New Command: Load Package
33
34 New Command: Load Package
35 =========================
36
37 Using the 'load' command we can use many ring source files in the same project
38
39 But all of these files will share the same global scope 
40
41 Now we have the "Load Package" command too
42
43 Using "Load Package" we can load a library (*.ring file) in new global scope
44
45 This is very useful to create libraries that avoid conflicts in global variables
46
47 Example:
48
49 File: loadpackage.ring
50
51 .. code-block:: ring
52
53         x = 100
54         ? "Hello, World!"
55         load package "testloadpackage.ring"
56
57         ? x
58         test()
59
60 File: testloadpackage.ring
61
62 .. code-block:: ring
63
64         ? "Hello from testloadpackage.ring"
65
66         x = 1000
67
68         test()
69
70         func test
71                 ? x
72
73 Output:
74
75 .. code-block:: none
76
77         Hello, World!
78         Hello from testloadpackage.ring
79         1000
80         100
81         1000
82
83
84
85 .. index:: 
86         pair: What is new in Ring 1.7?; ringvm_see() and ringvm_give() functions
87
88 ringvm_see() and ringvm_give() functions
89 ========================================
90
91 Using the ringvm_see() function we can redefine the behavior of the See command
92
93 Also we can use ring_see() to have the original behavior
94
95 Example:
96
97 .. code-block:: ring
98
99         see "Hello world" + nl
100         see 123 + nl
101         see ["one","two","three"]
102         see new point {x=10 y=20 z=30} 
103
104         func ringvm_see t
105                 ring_see("We want to print: ")
106                 ring_See(t)
107
108         class point x y z
109
110 Output:
111
112 .. code-block:: none
113
114         We want to print: Hello world
115         We want to print: 123
116         We want to print: one
117         two
118         three
119         We want to print: x: 10.000000
120         y: 20.000000
121         z: 30.000000
122
123 Using the ringvm_give() function we can redefine the behavior of the Give command
124
125 Also we can use ring_give() to have the original behavior
126
127 Example:
128
129 .. code-block:: ring
130
131         see "Name: " give name
132         see "Hello " + name
133
134         func ringvm_give
135                 see "Mahmoud" + nl
136                 return "Mahmoud"
137
138 Output:
139
140 .. code-block:: ring
141
142         Name: Mahmoud
143         Hello Mahmoud
144
145 .. index:: 
146         pair: What is new in Ring 1.7?; ring_state_new() and ring_state_mainfile() functions
147
148 ring_state_new() and ring_state_mainfile() functions
149 ====================================================
150
151 Using ring_state_new() and ring_state_mainfile() we can run Ring programs from Ring programs
152
153 But unlike ring_state_main(), Here we can control when to delete the Ring state!
154
155 This is important when we run GUI programs from GUI programs
156
157 Because they will share the GUI Library (RingQt), And In this case the caller will call
158
159 qApp.Exec()
160
161 So the sub program, will not stop and will return to the Main program
162
163 Here deleting the State of the sub programs will lead to a problem when we run the sub program events
164
165 So keeping the state is important for sub GUI programs hosted in GUI programs.
166
167
168 .. index:: 
169         pair: What is new in Ring 1.7?; Better Trace Library
170
171 Better Trace Library
172 ====================
173
174 The Trace library is updated, In the Debugger at break points we have now the "callstack" command
175
176 This command will print the functions call stack.
177
178 Example:
179
180 .. code-block:: ring
181
182         load "tracelib.ring"
183
184         func main
185                 ? "Hello from main!"
186                 test1()
187
188         func test1 
189                 ? "Hello from test1!"
190                 test2()
191
192         func test2 
193                 ? "Hello from test2!"
194                 test3()
195
196         func test3 
197                 ? "Hello from test3!"
198                 breakpoint()
199
200
201 .. image:: callstack.png
202         :alt: Call Stack
203
204 .. index:: 
205         pair: What is new in Ring 1.7?; Better Ring Notepad
206
207 Better Ring Notepad
208 ===================
209
210 Ring Notepad comes with the next updates
211
212 (1) Support *.cf extension
213 (2) Using Hash function (SHA256) for better "Save Changes?" message
214 (3) Ring Notepad - X Button - Ask for saving changes?
215
216
217 .. index:: 
218         pair: What is new in Ring 1.7?; Better RingQt
219
220 Better RingQt
221 =============
222
223 The next classes are added to RingQt
224
225 (1)  QStackedWidget
226 (2)  QCalendarWidget
227 (3)  QOpenGLFunctions
228 (4)  QOpenGLContext
229 (5)  QSurfaceFormat
230 (6)  QOpenGLWidget
231 (7)  QOpenGLVersionProfile
232 (8)  QOpenGLFunctions_3_2_Core
233 (9)  QVector2D
234 (10) QVector3D
235 (11) QVector4D
236 (12) QQuaternion
237 (13) QMatrix4x4
238 (14) QOpenGLPaintDevice
239 (15) QPaintDevice
240 (16) QOpenGLTimerQuery
241 (17) QOpenGLDebugLogger
242 (18) QOpenGLFramebufferObject
243 (19) QOpenGLVertexArrayObject
244 (20) QOpenGLBuffer
245 (21) QOpenGLShaderProgram
246 (22) QOpenGLShader
247 (23) QOpenGLTexture
248
249 .. index:: 
250         pair: What is new in Ring 1.7?; Better Ring2EXE
251
252 Better Ring2EXE
253 ===============
254
255 Ring2EXE is updated to works as expected when we don't have a C/C++ compiler
256
257 Where we can distribute applications and get (exe file and ringo file) in this case.
258
259
260 .. index:: 
261         pair: What is new in Ring 1.7?; Better RingZip
262
263 Better RingZip
264 ==============
265
266 The library is updated to support extracting files contains sub folders!
267
268 .. index:: 
269         pair: What is new in Ring 1.7?; Better Documentation
270
271 Better Documentation
272 ====================
273
274 (1) RingQt Classes Chapter - The classes are sorted.
275
276
277 .. index:: 
278         pair: What is new in Ring 1.7?; Better Ring VM
279
280 Better Ring VM
281 ==============
282
283 (1) Better Error Message
284 (2) List2Str() function support lists contains numbers
285 (3) Correct support for numbers contains _ as separator
286 (4) Creating lists without variables (statement --> Expression --> List)
287 (5) IsNULL() - Not case sensitive - treat Null and null like NULL
288 (6) Support adding the Self object to an attribute in this object
289 (7) Using ':' operator then keyword will create lower case literal 
290 (8) Printing objects - respect decimals() function
291 (9) When literal is not closed - determine the start of the literal
292 (10) Better message when printing objects contains lists
293 (11) VarPtr() - Support getting a pointer to variables in the local scope
294 (12) replace performance instructions with normal instructions when creating new threads
295
296 .. index:: 
297         pair: What is new in Ring 1.7?; RingLibuv Extension
298
299 RingLibuv Extension
300 ===================
301
302 Ring 1.7 comes with the RingLibuv extension
303
304 Libuv is a multi-platform support library with a focus on asynchronous I/O.
305
306 Example (Events Loop):
307
308 .. code-block:: ring
309
310         load "libuv.ring"
311
312         counter = 0
313         idler = NULL 
314
315         func main
316                 idler = new_uv_idle_t()
317                 uv_idle_init(uv_default_loop(), idler)
318                 uv_idle_start(idler, "wait()")
319                 ? "Idling..."
320                 uv_run(uv_default_loop(), UV_RUN_DEFAULT);
321                 uv_loop_close(uv_default_loop());
322                 destroy_uv_idle_t(idler)
323
324         func wait
325                 counter++
326                 if counter >= 100000
327                         uv_idle_stop(idler)
328                 ok
329
330 Output:
331
332 .. code-block:: none
333
334         Idling...
335
336 Example (Server):
337
338 .. code-block:: ring
339
340         load "libuv.ring"
341         load "objectslib.ring"
342
343         ? "Testing RingLibuv - Server Side - Using Classes"
344
345         open_object(:MyServer)
346
347         class MyServer from ObjectControllerParent
348
349                 DEFAULT_PORT    = 13370
350                 DEFAULT_BACKLOG = 1024
351                 
352                 addr    = new_sockaddr_in()
353                 server  = NULL
354                 client  = NULL
355                 myloop  = NULL
356                 
357                 func start
358                         myloop = uv_default_loop()
359                         server = new_uv_tcp_t()
360                         uv_tcp_init(myloop, server)
361                         uv_ip4_addr("127.0.0.1", DEFAULT_PORT, addr)
362                         uv_tcp_bind(server, addr, 0)
363                         r = uv_listen(server, DEFAULT_BACKLOG, Method(:newconnection) )
364                         if r 
365                                 ? "Listen error " + uv_strerror(r)
366                                 return 1
367                         ok
368                         uv_run(myloop, UV_RUN_DEFAULT)
369                         destroy_uv_tcp_t(server)
370                         destroy_uv_sockaddr_in(addr)
371                 
372                 func newconnection
373                         ? "New Connection"
374                         aPara   = uv_Eventpara(server,:connect)
375                         nStatus = aPara[2]
376                         if nStatus < 0
377                                 ? "New connection error : " + nStatus 
378                                 return 
379                         ok
380                         client = new_uv_tcp_t()
381                         uv_tcp_init(myloop, client)
382                         if uv_accept(server, client) = 0 
383                                         uv_read_start(client, uv_myalloccallback(), 
384                                                                 Method(:echo_read))
385                         ok
386                 
387                 func echo_read 
388                         aPara = uv_Eventpara(client,:read)
389                         nRead = aPara[2]
390                         buf   = aPara[3]
391                         if nRead > 0
392                                 req = new_uv_write_t()
393                                         wrbuf = uv_buf_init(get_uv_buf_t_base(buf), nread)
394                                 uv_write(req, client, wrbuf, 1, Method(:echo_write))
395                                 ? uv_buf2str(wrbuf)
396                                 message = "message from the server to the client"
397                                 buf = new_uv_buf_t()
398                                 set_uv_buf_t_len(buf,len(message))
399                                 set_uv_buf_t_base(buf,varptr("message","char *"))
400                                 uv_write(req, client, buf, 1, Method(:echo_write))
401                         ok
402                 
403                 func echo_write
404                         aPara = uv_Eventpara(client,:read)
405                         req   = aPara[1]
406         
407
408 Output:
409
410 When we run the client, We will see the message "New Connection"
411
412 Then the message "hello from the client"
413
414 .. code-block:: none
415
416         Testing RingLibuv - Server Side - Using Classes
417         New Connection
418         hello from the client
419
420 Example (Using Threads):
421
422 .. code-block:: ring
423
424         load "libuv.ring"
425         load "objectslib.ring"
426
427         ? "Testing RingLibuv - Threads - Using Classes"
428
429         open_object(:MyThreads)
430
431         class MyThreads from ObjectControllerParent
432
433                 func Start
434                         one_id = new_uv_thread_t()
435                         two_id = new_uv_thread_t()
436                         uv_thread_create(one_id, Method(:One))
437                         uv_thread_create(two_id, Method(:Two))
438                         uv_thread_join(one_id)
439                         uv_thread_join(two_id)
440                         destroy_uv_thread_t(one_id)
441                         destroy_uv_thread_t(two_id)
442                 
443                 func one
444                         ? "Message from the First Thread!"
445                 
446                 func Two
447                         ? "Message from the Second Thread!"
448                 
449
450 Output:
451
452 .. code-block:: none
453
454         Testing RingLibuv - Threads - Using Classes
455         Message from the First Thread!
456         Message from the Second Thread!
457
458 For more information about this extension (RingLibuv) check the chapter: Using RingLibuv