Anda di halaman 1dari 10

Ring Documentation, Release 1.

The generated source code file (ring_allegro.c) is around 12,000 Lines of code (12 KLOC)
While the configuration file is less than 1 KLOC
To build the library (create the DLL files)
https://github.com/ring-lang/ring/blob/master/extensions/ringallegro/buildvc.bat
Also you can check this extension for the LibSDL Library
https://github.com/ring-lang/ring/tree/master/extensions/ringsdl
After this know you should know about
1 - Writing the configuration file
2 - Using the Code Generator
3 - Building your library/extension
4 - Using your library/extension from Ring code
Let us move now to you question about Qt
We have RingQt which is just an extension to ring (ringqt.dll)
You dont need to modify Ring.
1. You just need to modify RingQt
2. Or extend Ring with another extension based on Qt (but the same Qt version)
For the first option see the RingQt extension
https://github.com/ring-lang/ring/tree/master/extensions/ringqt
Configuration file
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/qt.cf
To generate the source code
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.bat
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencode.sh
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/gencodeandroid.bat
To build the DLL/so/Dylib files
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildmingw32.bat
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildgcc.sh
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/buildclang.sh
Study RingQt
Learn about the options that you have
1. wrapping a Qt class directly
2. Creating a new class then wrapping your new class
For the second option (in the previous two points or in the two points before that)
You will create new classes in C++ code
Then you merge these classes to RingQt or provide special DLL for them (your decision)
If your work is general (will help others) just put it to RingQt.

63.48. How to extend RingQt and add more classes? 770


Ring Documentation, Release 1.2

if your work is special (to specific application) just put it in another extension.

63.49 How to add Combobox and other elements to the cells of a


QTableWidget?

Check the next code


Load "guilib.ring"
New qApp
{
win1 = new qMainWindow() {
setGeometry(100,100,1100,370)
setwindowtitle("Using QTableWidget")

Table1 = new qTableWidget(win1) {


setrowcount(10) setcolumncount(10)
setGeometry(0,0,800,400)
setselectionbehavior(QAbstractItemView_SelectRows)

for x = 1 to 10
for y = 1 to 10
item1 = new qtablewidgetitem("R"+X+"C"+Y)
setitem(x-1,y-1, item1)
next
next

cmb = new QComboBox(Table1) {


alist = ["one","two","three","four","five"]
for x in aList additem(x,0) next
}
setCellWidget(5, 5, cmb)
}

setcentralwidget(table1)
show()
}
exec()
}

63.50 How to perform some manipulations on selected cells in


QTableWidget?

Check the next sample


Load "guilib.ring"

New qApp {
win1 = new qMainWindow() {
setGeometry(100,100,800,600)
setwindowtitle("Using QTableWidget")
Table1 = new qTableWidget(win1) {
setrowcount(10) setcolumncount(10)
setGeometry(10,10,400,400)

63.49. How to add Combobox and other elements to the cells of a QTableWidget? 771
Ring Documentation, Release 1.2

for x = 1 to 10
for y = 1 to 10
item1 = new qtablewidgetitem("10")
setitem(x-1,y-1,item1)
next
next
}
btn1 = new qPushButton(win1) {
setText("Increase")
setGeometry(510,10,100,30)
setClickEvent("pClick()")
}
show()
}
exec()
}

func pClick
for nRow = 0 to Table1.rowcount() - 1
for nCol = 0 to Table1.columncount() - 1
Table1.item(nRow,nCol) {
if isSelected()
setText( "" + ( 10 + text()) )
ok
}
next
next

63.50. How to perform some manipulations on selected cells in QTableWidget? 772


CHAPTER

SIXTYFOUR

LANGUAGE REFERENCE

In this chapter we will learn about


Language keywords
Language Functions
Compiler Errors
Runtime Errors
Language Grammar
Virtual Machine (VM) Instructions

64.1 Language Keywords

Keywords Count : 46
again
and
but
bye
call
case
catch
changeringkeyword
changeringoperator
class
def
do
done
else
elseif
end
exit

773
Ring Documentation, Release 1.2

for
from
func
get
give
if
import
in
load
loadsyntax
loop
new
next
not
off
ok
on
or
other
package
private
put
return
see
step
switch
to
try
while

64.2 Language Functions

Functions Count : 217


acos() add() addattribute() adddays() addmethod() ascii()
asin() assert()
atan() atan2() attributes() binarysearch() callgc() ceil()
cfunctions() char()
chdir() classes() classname() clearerr() clock() clockspersecond()

64.2. Language Functions 774


Ring Documentation, Release 1.2

closelib() copy()
cos() cosh() currentdir() date() dec() decimals() decrypt() del()
diffdays() dir() download() encrypt() eval() exefilename()
exefolder() exp()
fabs() fclose() feof() ferror() fexists() fflush() fgetc() fgetpos()
fgets() filename() find() floor() fopen() fputc() fputs() fread()
freopen() fseek() fsetpos() ftell() functions() fwrite()
getattribute() getchar()
globals() hex() hex2str() input() insert() intvalue() isalnum() isalpha()
isandroid() isattribute() iscfunction() isclass() iscntrl()
isdigit() isfreebsd() isfunction()
isglobal() isgraph() islinux() islist() islocal()
islower() ismacosx() ismethod()
ismsdos() isnull() isnumber() isobject() ispackage()
ispackageclass() isprint() isprivateattribute()
isprivatemethod() ispunct() isspace() isstring()
isunix() isupper() iswindows() iswindows64()
isxdigit() left() len() lines() list() list2str() loadlib() locals()
log() log10() lower() max() md5() mergemethods() methods() min()
murmur3hash() mysql_autocommit() mysql_close()
mysql_columns() mysql_commit() mysql_connect() mysql_error()
mysql_escape_string()
mysql_info() mysql_init() mysql_insert_id() mysql_next_result()
mysql_query() mysql_result() mysql_result2() mysql_rollback()
nullpointer() number() object2pointer() objectid()
odbc_autocommit() odbc_close() odbc_colcount() odbc_columns()
odbc_commit() odbc_connect() odbc_datasources()
odbc_disconnect() odbc_drivers() odbc_execute() odbc_fetch() odbc_getdata()
odbc_init() odbc_rollback() odbc_tables() packageclasses()
packages() perror() pointer2object() pow()
prevfilename() ptrcmp() raise() randbytes() random()
read() remove() rename()
reverse() rewind() right() ringvm_calllist()
ringvm_cfunctionslist() ringvm_classeslist()
ringvm_fileslist() ringvm_functionslist()
ringvm_memorylist() ringvm_packageslist() sendemail()
setattribute() sha1() sha224() sha256() sha384()
sha512() sin() sinh() sort() space() sqlite_close()
sqlite_errmsg() sqlite_execute()
sqlite_init() sqlite_open() sqrt() str2hex() str2list()
strcmp() string() substr()
sysget() system() tan() tanh() tempfile() tempname() time() timelist()
trim() type() ungetc() unsigned() upper() varptr() version() windowsnl()

64.3 Compiler Errors

Error (C1) : Error in parameters list, expected identifier


Error (C2) : Error in class name
Error (C3) : Unclosed control strucutre, ok is missing
Error (C4) : Unclosed control strucutre, end is missing
Error (C5) : Unclosed control strucutre, next is missing
Error (C6) : Error in function name

64.3. Compiler Errors 775


Ring Documentation, Release 1.2

Error (C7) : Error in list items


Error (C8) : Parentheses ) is missing
Error (C9) : Brackets ] is missing
Error (C10) : Error in parent class name
Error (C11) : Error in expression operator
Error (C12) :No class definition
Error (C13) : Error in variable name
Error (C14) : Try/Catch miss the Catch keyword!
Error (C15) : Try/Catch miss the Done keyword!
Error (C16) : Error in Switch statement expression!
Error (C17) : Switch statement without OFF
Error (C18) : Missing closing brace for the block opened!
Error (C19) : Numeric Overflow!
Error (C20) : Error in package name
Error (C21) : Unclosed control strucutre, again is missing
Error (C22) : Function redefinition, function is already defined!
Error (C23) : Using ( after number!
Error (C24) : The parent class name is identical to the subclass name
Error (C25) : Trying to access the self reference after the object name

64.4 Runtime Errors

Error (R1) : Cannt divide by zero !


Error (R2) : Array Access (Index out of range) !
Error (R3) : Calling Function without definition !
Error (R4) : Stack Overflow !
Error (R5) : Cant access the list item, Object is not list !
Error (R6) : Variable is required
Error (R7) : Cant assign to a string letter more than one character
Error (R8) : Variable is not a string
Error (R9) : Using exit command outside loops
Error (R10) : Using exit command with number outside the range
Error (R11) : error in class name, class not found!
Error (R12) : error in property name, property not found!
Error (R13) : Object is required
Error (R14) : Calling Method without definition !

64.4. Runtime Errors 776


Ring Documentation, Release 1.2

Error (R15) : error in parent class name, class not found!


Error (R16) : Using braces to access unknown object !
Error (R17) : error, using Super without parent class!
Error (R18) : Numeric Overflow!
Error (R19) : Calling function with less number of parameters!
Error (R20) : Calling function with extra number of parameters!
Error (R21) : Using operator with values of incorrect type
Error (R22) : Using loop command outside loops
Error (R23) : Using loop command with number outside the range
Error (R24) : Using uninitialized variable
Error (R25) : Error in package name, Package not found!
Error (R26) : Calling private method from outside the class
Error (R27) : Using private attribute from outside the class
Error (R28) : Using bad data type as step value
Error (R29) : Using bad data type in for loop
Error (R30) : parent class name is identical to child class name
Error (R31) : Trying to destory the object using the self reference
Error (R32) : The CALL command expect a variable contains string!
Error (R33) : Bad decimals number (correct range >= 0 and <=14) !
Error (R34) : Variable is required for the assignment operation
Error (R35) : Cant create/open the file!
Error (R36) : The column number is not correct! Its greater than the number of columns in the list

64.5 Language Grammar

Program > {statement}


Statement > package <Identifier> { . <Identifier> }
Statement > class <Identifier> [ from <Identifier> ]
Statement > func|def <Identifier> [ParaList]
Statement > import <Identifier> { . <Identifier> }
Statement > private
Statement > load <Literal>
Statement > loadsyntax <Literal>
Statement > changeringkeyword <OldKeyword> <NewKeyword>
Statement > changeringoperator <OldOperator> <NewOperator>
Statement > see|put <Expr>

64.5. Language Grammar 777


Ring Documentation, Release 1.2

Statement > give|get <Identifier>


Statement > if <Expr> [{] {statement} [ {but|elseif <Expr> {Statement} } ] [else {Statement} ]
ok|end|}
Statement > Switch <Expr> [{] { on|case <Expr> {statement} } [other {Statement} ] off|end|}
Statement > for <Identifier> = <Expr> to <Expr> [ step <Expr> ] [{] {Statement} next|end|}
Statement > for <Identifier> in <Expr> [ step <Expr> ] [{] {statement} next|end|}
Statement > while <Expr> [{] {statement} end|}
Statement > do {statement} again <Expr>
Statement > try {statement} [{] catch {statement} done|end|}
Statement > return <Expr>
Statement > bye
Statement > exit
Statement > loop
Statement > <Expr>
Statement > epslion
ParaList > epslion
ParaList > [(] <Identifier> [{ , <Identifier> }] [)]
Expr > <LogicNot> [{ and|or <LogicNot> }]
LogicNot > [not] <EqualOrNot>
EqualOrNot > [ =|!= ] <Compare>
Compare > <BitOrXor> [ { < | > | <= | >= <BitOrXor> } ]
BitOrXor > <BitAnd> [ { | | ^ <BitAnd> } ]
BitAnd > <BitShift> [ { & <BitShift> } ]
BitShift > <Arithmetic> [ { << | >> <Arithmetic> } ]
Arithmetic > <Term> [ { + | - <Term> } ]
Term > <Range> [ { * | / | % <Range> } ]
Range > <Factor> [ : <Factor> ]
Factor > <Identifier> [ {Mixer} ] [ = <Expr> ]
Factor > <Number>
Factor > <Literal>
Factor > : <Identifier>
Factor > - <Expr>
Factor > ( <Expr> )
Factor > <List>
Factor > new <Identifier>
Factor > <AnonymousFunction>

64.5. Language Grammar 778


Ring Documentation, Release 1.2

Factor > call <identifier> { . <Identifier> } ( <Parameters> )


List > [ [ <Expr> { , <Expr> } ] ]
Mixer > { . <Identifier> }
Mixer > [ <Expr> ]
Mixer > ( [ <Expr> [ { , <Expr> }] ] )
Mixer > { {Statement} }
AnonymousFunction > func|def| [<ParaList>] { {Statement} }

64.6 Virtual Machine (VM) Instructions

Definitions :-
VM : Virtual Machine
Stack : VM Stack
IR : Instruction Register
PC : Program Counter
VP : Variable Pointer
Stack[nSize] : Last Item in the Stack (Last In - First Out)
VV : Variable Value (We have a Pointer to a variable, And we access this variable value)
(Stack and Variables)

64.6. Virtual Machine (VM) Instructions 779

Anda mungkin juga menyukai