BASIC Developer & Support Resources > Scripting Languages

ScriptBasic Windows 32

<< < (2/4) > >>

John:
This is an example of a dynamic virtual DLL function using DLLC. This example also shows the dynamic FFI definition and call feature.

FYI: ScriptBasic can also run a a DLL resource. Your application could embed ScriptBasic which gives you a JIT BASIC compiler as well.  8)


--- Code: Script BASIC ---' Virtual DLL Functions include dllc.sbi oxy=dllfile("oxygen.dll") o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )o2_error = dllproc( oxy, "o2_error c*=()         " )o2_errno = dllproc( oxy, "o2_errno i =()         " )o2_len   = dllproc( oxy, "o2_len   i =()         " )o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " ) dllcall o2_mode,1  src="""extern function funA(char* s) as char*  static char c[256]  c="Hello "+s  return cend function function funB(char*s) as char*  static char c[256]  c="Goodbye "+s  return cend function function reverse(char*s)  byte b at (strptr s)  sys i,d,e,j,t  e=len s  d=e>>1  for i=1 to d    j=e-i+1    t=b[i] : b[i]=b[j] : b[j]=t  nextend function sub finish()  terminateend sub function link(sys n) as sys  select n    case 0 : return @finish    case 1 : return @funA    case 2 : return @funB    case 3 : return @reverse  end selectend function end extern addr link"""  function oxygen(src)  dllcall o2_basic,src  if (dllcall(o2_errno)<>0) then    dllprnt dllcall(o2_error)    a=0  else    a=dllcall(o2_exec,0)  end if  oxygen=aend function a=oxygen(src) if (a<>0) then  Hello   = dllproc(a,"Hello   c*=(c*value) ", dllcald(a,1) )  Goodbye = dllproc(a,"Goodbye c*=(c*value) ", dllcald(a,2) )  Reverse = dllproc(a,"Reverse    (c*value) ", dllcald(a,3) )  Finish  = dllproc(a,"Finish     ()        ", dllcald(a,0) )    print dllcall(hello,"John") & "\n"  print dllcall(Goodbye,"John") & "\n"  s="abcdef"  print "Reversed " & s & " = "  dllcall(Reverse,s)  print s & "\n"  dllcall(Finish)end if dllfile 

C:\ScriptBASIC\examples>sbc dllco2_e.sb
Hello John
Goodbye John
Reversed abcdef = fedcba

C:\ScriptBASIC\examples>

John:
This is an example of using DLLC to call ASM based functions and methods.


--- Code: Script BASIC --- include dllc.sbi   oxy=dllfile("oxygen.dll")   o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )  o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )  o2_error = dllproc( oxy, "o2_error c*=()         " )  o2_errno = dllproc( oxy, "o2_errno i =()         " )  o2_len   = dllproc( oxy, "o2_len   i =()         " )  o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )   dllcall o2_mode,1   function oxygen(src)  dllcall o2_basic,src  if (dllcall(o2_errno)<>0) then    dllprnt dllcall(o2_error)    a=0    line input q  else    a=dllcall(o2_exec,0)  end if  oxygen=a  end function  ' ==============================  src="""  extern   function reverse(char*s)  ========================  addr ecx,s  mov edx,0 .rlen  mov al,[ecx]  cmp al,0  jz xlen  inc edx  inc ecx  jmp rlen .xlen  ;  addr ecx,s  add  edx,ecx  dec ecx  ; .rswap  inc ecx  dec edx  cmp edx,ecx  jle xswap  mov al,[ecx]  mov ah,[edx]  mov [ecx],ah  mov [edx],al  jmp rswap .xswap  end function   function getword(char*ss,sys*b) as char*  '=======================================  sys a  if not @ss then return ""  if b=0 then b=1  byte s at @ss  byte c,d  sys bb,bc  static char z[128]  a=0  bb=b  '  'SKIP LEADING SPACES  do    c=s[b]    select c    case 33 to 255,0 : exit do 'SKIP SPACE    end select    b++  end do  bc=b  '  'QUOTES  select c  case 34,39   do      b+=1      d=s[b]      if d=0 or d=c then b+=1 : jmp fwd done   end do  end select  'WORDS AND SYMBOLS  do    c=s[b]    select c    case 0 to 32     : exit do    case 35          : jmp fwd more    case 33  to 47   : 'symbols    case 48  to 57   : jmp fwd more 'numbers    case 58  to 64   : 'symbols    case 65  to 90   : jmp fwd more 'capitals    case 95          : jmp fwd more 'underscore    case 91  to 96   : 'symbols    case 97  to 122  : jmp fwd more 'lower case    case 123 to 127  : 'symbols    case 128 to 255  : jmp fwd more 'higher ascii    end select    '    if b=bc then b++    exit do    '    more:    b++  end do  '  done:  '  if b>bb then    z=mid ss,bc,b-bc  else    z=""  end if  return z   end function  =================Class AlignedText================= indexbase 1 string  buf, bufo, pr, cr, tab, jus, dlmsys     Cols, Rows, ColWidth[0x100], TotWidth, ColPad, ld method SetText(char*s)======================if not len cr then cr=chr(13,10)tab=chr(9)if not len jus then jus=string 200,"L"buf=smeasureend method  method measure()================sys a, b, wa, wb, cm, c, cw, ia=1 : b=1Cols=0 : Rows=0 : ColPad=3ld=len dlmif not ld then dlm="," : ld=1 'default to commado  wb=b  a=instr b,buf,cr  if a=0 then exit do  cm=0  c++  do    wa=instr wb,buf,dlm    if wa=0 or wa>a then exit do    cm++    if cm>cols then cols=cm    cw=wa-wb    if cw > ColWidth[cm] then ColWidth[cm]=cw    wb=wa+ld  end do  b=a+len crend dorows=c'c=0for i=1 to cols  ColWidth[ i ]+=ColPad  c+=ColWidth[ i ]nextTotWidth=c+len cr'print ShowMetricsend method  method ShowMetrics() as char*=============================sys ipr="METRICS:" cr crpr+=rows tab cols tab totwidth cr crpr+="column" tab "spacing" crfor i=1 to cols  pr+=i tab ColWidth[ i ] crnextreturn prend method  method justify(char*j)======================jus=jend method method delimiter(char*j)========================dlm=jend method method endofline(char*j)========================cr=jend method  method layout() as char*========================sys a, b, wa, wb, wl, cm, lpos, cpos, pbufo=space Rows*TotWidtha=1 : b=1do  wb=b  a=instr(b,buf,cr)  if a=0 then exit do  cm=0  cpos=1  do    wa=instr(wb,buf,dlm)    if wa=0 or wa>a then exit do    '    cm++    '    'JUSTIFICATION    '    wl=wa-wb    p=lpos+cpos 'default "L" LEFT ALIGN    '    select case asc(jus,cm)      case "R" : p=lpos+cpos+ColWidth[cm]-wl-Colpad      case "C" : p=lpos+cpos+( ColWidth[cm]-wl-Colpad )*.5    end select    '    mid bufo,p, mid buf,wb,wl    cpos+=colwidth[cm]    wb=wa+ld  end do  b=a+len cr  lpos+=TotWidth  if lpos<len(bufo) then mid bufo,lpos-1,crend doreturn bufoend method'end class '#recordof AlignedText   AlignedText atxt   function AlignText(char *in,*ju,*dl,*cr) as char*  =================================================  atxt.justify         ju  atxt.delimiter       dl  atxt.endofline       cr  atxt.SetText         in  return               atxt.layout  end function    sub finish()  ============  terminate  end sub     function link(sys n) as sys  ===========================  select n  case 0 : return @finish  case 1 : return @reverse  case 2 : return @getword  case 3 : return @aligntext  end select  end function   end extern     addr link  """' ==============================   '  a=oxygen(src)  '  if (a<>0) then  '' ==============================  '  Finish    = dllproc(a,"Finish     ()        ", dllcald(a,0) )  Reverse   = dllproc(a,"Reverse    (c*value) ", dllcald(a,1) )  GetWord   = dllproc(a,"GetWord c*=(c*value,i*index) ", dllcald(a,2) )  AlignText = dllproc(a,"AlignText c*=(c*in,c*jus,c*dlm,c*cr) ", dllcald(a,3) )  '' ==============================  '  s="abcdef1234567"  print "Reversed " & s & " = "  dllcall(Reverse,s)  print s & "\n"  '  '  s="one two three"  i=1  dllcall(GetWord,s,i)  print dllcall(GetWord,s,i) & "\n"  dllcall(GetWord,s,i)   s="""Given;;a;;text;;file;;of;;many;;lines,;;where;;fields;;within;;a;;line;;are;;delineated;;by;;a;;single;;'dollar';;character,;;write;;a;;programthat;;aligns;;each;;column;;of;;fields;;by;;ensuring;;that;;words;;in;;each;;column;;are;;separated;;by;;at;;least;;one;;space.Further,;;allow;;for;;each;;word;;in;;a;;column;;to;;be;;either;;left;;justified,;;right;;justified,;;or;;center;;justified;;within;;its;;column."""   lf="\n" & chr(0)  dl=";;"  fm="LLLLCCCRRRRR"   ' t=dllcall(AlignText,s,fm,dl,lf )  t=dllcall(AlignText,s,"LLLLCCCRRRRR",";;","\n" & chr(0) )  print t & "\n"   dllcall(Finish)  '  end if  dllfile 
Output

C:\ScriptBASIC\examples>sbc dllco2asm.sb
Reversed abcdef1234567 = 7654321fedcba
two

 Given        a            text         file       of       many        lines,        where   fields   within        a   line
 are          delineated   by           a        single   'dollar'    character,      write        a
 that         aligns       each         column     of       fields        by       ensuring     that    words       in   each
 column       are          separated    by         at       least         one
 Further,     allow        for          each      word        in          a          column       to       be   either   left
 justified,   right        justified,   or       center   justified     within          its

C:\ScriptBASIC\examples>

John:
This will be my last DLLC post. This example shows other features of DLLC like COM, BSTR, wide string, structures and more.


--- Code: Script BASIC ---' PROPOSED ALTERNATIVE TO DYC' supporting variables passed by reference' supporting compound types' supporting compound variables stored in SB strings ' supported types:' b bool' c char' d double precision float' f float' h handle' i integer (32bit)' p pointer' s short (16bit) integer' z null terminated string ' supported calling conventions' cdecl' stdcall ' * signifies pass variable by reference, otherwise by value ' SB INTERFACE   declare sub dllerrc alias "dllerrc" lib "DLLC"  declare sub dllerrs alias "dllerrs" lib "DLLC"  declare sub dllreco alias "dllreco" lib "DLLC"  declare sub dllfile alias "dllfile" lib "DLLC"  declare sub dllproc alias "dllproc" lib "DLLC"  declare sub dllprog alias "dllprog" lib "dllc"  declare sub dllendp alias "dllendp" lib "dllc"  declare sub dllmeth alias "dllmeth" lib "DLLC"  declare sub dllcall alias "dllcall" lib "DLLC"  declare sub dllcalt alias "dllcalt" lib "DLLC"  declare sub dllcobj alias "dllcobj" lib "DLLC"  declare sub dllcobt alias "dllcobt" lib "DLLC"  declare sub dllclbk alias "dllclbk" lib "DLLC"  declare sub dlltype alias "dlltype" lib "DLLC"  declare sub dlldimv alias "dlldimv" lib "DLLC"  declare sub dllfill alias "dllfill" lib "DLLC"  declare sub dllgetm alias "dllgetm" lib "DLLC"  declare sub dllputm alias "dllputm" lib "DLLC"  declare sub dlldelo alias "dlldelo" lib "DLLC"  declare sub dllostr alias "dllostr" lib "DLLC"  declare sub dllzstr alias "dllzstr" lib "DLLC"  declare sub dllastr alias "dllastr" lib "DLLC"  declare sub dllwstr alias "dllwstr" lib "DLLC"  declare sub dllcast alias "dllcast" lib "DLLC"  declare sub dllguid alias "dllguid" lib "DLLC"  declare sub dllsecs alias "dllsecs" lib "DLLC"  declare sub dlltran alias "dlltran" lib "DLLC"  declare sub dllclos alias "dllclos" lib "DLLC"  'TYPES ' B boolean' C character' D double precision float' F single precision float' H handle' I integer' L long (4 byte) integer' O bstring (as handle)' Q quad integer (yet to be resolved)' P pointer' S short (2 byte) integer' T user defined type' Z sb zstring / SB string ' add '*' for ptr/ passing byref 'TITLE print "DLLC SPEC / DEMO / TESTS:\n\n" s=space(&h100)  'LOADING LIBRARIES   mylib=dllfile("DLLCtestDLL.dll")  ole32=dllfile("ole32.dll")'print mylib & "\n" 'MEASURING TIME FRACTIONAL SECONDS t1=dllsecs() 'DECLARING PROCEDURES stringbuf        = dllproc(mylib,"stringbuf stdcall i=(c*buf, i bufsize) " )doublebyref      = dllproc(mylib,"doublebyref (d*num)"           )longbyref        = dllproc(mylib,"longbyref (l*num)"             )returnbstring    = dllproc(mylib,"returnbstring o=()"            )rectanglearea    = dllproc(mylib,"rectanglearea i=(t*rectangle)" )showguid         = dllproc(mylib,"showguid z=(t*guidinput,t*guidinput)"      ) 'TRAP ERRORS if dllerrc() then  print "DLLC logged errors: " & dllerrc() & "\n" & dllerrs()  goto endingend if 'DECLARE MORE PROCEDURES FOR COM CoInitialize     = dllproc(ole32,"CoInitialize (i)")CoUninitialize   = dllproc(ole32,"CoUninitialize (i)")CoCreateInstance = dllproc(ole32,"CoCreateInstance i=(t*ObjGuid ,i pUnkOuter,i context, t*IspGuid, i*Iface)" ) 'TRAP ERRORS if dllerrc() then  print "DLLC logged errors: " & dllerrc() & "\n" & dllerrs()  goto endingend if  'COM SPEECH VoiceObjGuid = dllguid("96749377-3391-11D2-9EE3-00C04F797396")ISpVoiceGuid = dllguid("6C44DF74-72B9-4992-A1EC-EF996E0422D4")Context      = 7pUnkOuter    = 0Voice        = 0Release      = dllmeth( 2,"Release i=()")Speak        = dllmeth(20,"Speak i=(z*pwcs,i flags,i pulstreamno)")WaitUntilDone= dllmeth(32,"WaitUntilDone i=(i)")print dllreco(speak)Text         = dllwstr("Hello Everyone!\0")hr=0dllcall(CoInitialize,0)hr=dllcall(CoCreateInstance, VoiceObjGuid, pUnkouter, Context, ISpVoiceGuid, Voice)if (hr=0) then  print "connected to voice\n\n"  print dllastr(Text) & "\n\n"  dllcobj(Voice,Speak,Text,0,0)  dllcobj(Voice,WaitUntilDone,0xFFFFFFFF)  dllcobj(Voice,Release)else  print "SAPI Error " & format("%x",hr) & "\n\n"end if dllcall(CoUninitialize) 'TIMER t2=dllsecs()print "Lapsed time Secs: " & t2-t1 & "\n\n"  'SHOW DLLC RECORDS print dllreco(mylib) & "\n"print dllreco(stringbuf) & "\n"  'CREATING A COMPOUND TYPE rectangle=dlltype("rectangle (i left,i top, i right, i bottom)")print dllreco(rectangle) & "\n" 'CREATING A COMPOUND VARIABLE (ARRAY OF 2 UNITS) rect=dlldimv(rectangle,2) print "Length of rect variables record: (4+16*2) " & len(rect) & "\n" 'ASSIGNING VALUES dllfill(rect,10,20,30,40) 'READING A MEMBER VALUE w=dllgetm(rect,3)print "rect right (30) " & w & "\n" 'WRITING A MEMBER VALUE dllputm (rect,3,42)w=dllgetm(rect,3)print "rect right (42) " & w & "\n\n" 'CALLING SUBS z="Hello!" & space(100)dllcall(stringbuf,z,100)print z & "\n" a=42dllcall(longbyref,a)print a & "\n"a=1.25dllcall(doublebyref,a)print a & "\n"  'CALLING FUNCTIONS print "Rectangle Area: " & dllcall(rectanglearea,rect) & "\n"bs=dllcall(returnbstring)print "bstring handle: " & bs & "\n" 'SB STRING / OLE STRING CONVERSIONS z=dllzstr(bs)print z & "\n"bt=dllostr(z)print "bstring handle " & bt & "\n"y=dllzstr(bt)print y & "  (original bstring is auromatically freed) \n\n" 'EXPLICIT DISPOSAL OF BSTRING bs=dllostr("ABCDEF")print "new bstring: handle=" & bs & "\n"dlldelo(bs)print "dispose bstring: handle=" & bs & "\n\n"  'ASCII / WIDE CONVERSIONS az="abcdef"wz=dllwstr(az)print "Wide string (6 to 12) " & len(wz) & "\n"az=dllastr(wz)print "ascii string (12 to 6) " & len(az) & "\n"print az & "\n\n" 'GUID TEXT TO BINARY CONVERSION gu1=dllguid("{96749377-3391-11D2-9EE3-00C04F797396}")gu2=dllguid("{6C44DF74-72B9-4992-A1EC-EF996E0422D4}") print "GUID: " & dllcall(showguid,gu1,gu2) & "\n" 'PAUSE TO DISPLAY RESULTS'ending: 'FREE ALL DLLS USED BY DLLC dllfile 
Output

C:\ScriptBASIC\examples>sbc dllcfeatures.sb
DLLC SPEC / DEMO / TESTS:

raw: Speak i=(z*pwcs,i flags,i pulstreamno)
name          Speak
metatype      4
handle        80
library       0
par count     3
par bytes     12
stack release 0

Params/Members
1  0    z
2  4    I
3  8    I
Return: I
connected to voice

Hello Everyone!

Lapsed time Secs: 2.183793

raw:
name          DLLCtestDLL.dll
metatype      1
handle        7405568
library       0
par count     0
par bytes     0
stack release 0

Params/Members
Return:

raw: stringbuf stdcall i=(c*buf, i bufsize)
name          stringbuf
metatype      2
handle        7422288
library       1
par count     2
par bytes     8
stack release 0

Params/Members
1  0    c
2  4    I
Return: I

raw: rectangle (i left,i top, i right, i bottom)
name          rectangle
metatype      3
handle        0
library       0
par count     4
par bytes     16
stack release 0

Params/Members
1  0    I
2  4    I
3  8    I
4  12   I
Return:

Length of rect variables record: (4+16*2) 48
rect right (30) 30
rect right (42) 42

greeting from stringbffuf procedure / DLLtestDLL

84
2.500000
Rectangle Area: 660
bstring handle: 9578972
This was an OLE/Bstring
bstring handle 9578972
This was an OLE/Bstring  (original bstring is auromatically freed)

new bstring: handle=9578972
dispose bstring: handle=0

Wide string (6 to 12) 12
ascii string (12 to 6) 6
abcdef

GUID: {96749377-3391-11D2-9EE3-00C04F797396}
{6C44DF74-72B9-4992-A1EC-EF996E0422D4}


C:\ScriptBASIC\examples>

John:
The SBT extension module adds thread support to ScriptBasic. Actually SBT is a ScriptBasic embedding DLL using ScriptBasic as the host. It is similar to the sbhttpd application server that uses C as the host and handles the web protocol and running as a Windows service.

SBT Include

--- Code: Script BASIC ---' SBT (ScriptBasic Thread Extenstion) - Include File DECLARE SUB SB_New ALIAS "SB_New" LIB "sbt"DECLARE SUB SB_Configure ALIAS "SB_Configure" LIB "sbt"DECLARE SUB SB_Load ALIAS "SB_Load" LIB "sbt"DECLARE SUB SB_LoadStr ALIAS "SB_LoadStr" LIB "sbt"DECLARE SUB SB_Run ALIAS "SB_Run" LIB "sbt"DECLARE SUB SB_NoRun ALIAS "SB_NoRun" LIB "sbt"DECLARE SUB SB_ThreadStart ALIAS "SB_ThreadStart" LIB "sbt"DECLARE SUB SB_ThreadEnd ALIAS "SB_ThreadEnd" LIB "sbt"DECLARE SUB SB_GetVar ALIAS "SB_GetVar" LIB "sbt"DECLARE SUB SB_SetUndef ALIAS "SB_SetUndef" LIB "sbt"DECLARE SUB SB_SetInt ALIAS "SB_SetInt" LIB "sbt"DECLARE SUB SB_SetDbl ALIAS "SB_SetDbl" LIB "sbt"DECLARE SUB SB_SetStr ALIAS "SB_SetStr" LIB "sbt"DECLARE SUB SB_ResetVars ALIAS "SB_ResetVars" LIB "sbt"DECLARE SUB SB_msSleep ALIAS "SB_msSleep" LIB "sbt"DECLARE SUB SB_CallSub ALIAS "SB_CallSub" LIB "sbt"DECLARE SUB SB_CallSubArgs ALIAS "SB_CallSubArgs" LIB "sbt"DECLARE SUB SB_Destroy ALIAS "SB_Destroy" LIB "sbt"  
This example shows starting a ScriptBasic (asynchronous) thread, calling it's function and get/set variables. 


--- Code: Script BASIC ---' SBT Demo IMPORT sbt.sbi sb_code = """FUNCTION prtvars(a, b, c)  PRINT a,"\\n"  PRINT FORMAT("%g\\n", b)  PRINT c,"\\n"  prtvars = "Function Return"END FUNCTION a = 0b = 0c = """"" sb = SB_New()SB_Configure sb, "C:/Windows/SCRIBA.INI"SB_Loadstr sb, sb_codeSB_NoRun sb' Call function before running scriptfuncrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")PRINT funcrtn,"\n"' Run script initializing globalsSB_Run sb, ""' Assign variables valuesSB_SetInt sb, "main::a", 321SB_SetDbl sb, "main::b", 32.1SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)' Call function again with variables assigned in the previous stepSB_CallSubArgs sb, "main::prtvars", _          SB_GetVar(sb, "main::a"), _          SB_GetVar(sb, "main::b"), _          SB_GetVar(sb, "main::c")SB_Destroy sb 

C:\ScriptBASIC\examples>sbc sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One

C:\ScriptBASIC\examples>


This is an independent synchronous thread example running a FOR/NEXT loop in main and a thread.

sbt_main

--- Code: Script BASIC ---' SBT Main IMPORT sbt.sbi SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI") FOR x = 1 TO 10  PRINT "M:",x,"\n"  sb_msSleep(20)NEXT 
Thread

--- Code: Script BASIC ---' SBT Thread IMPORT sbt.sbi FOR x = 1 TO 10  PRINT "T:",x,"\n"  SB_msSleep(20)NEXT SB_ThreadEnd 
Output

C:\ScriptBASIC\examples>sbc sbt_main.sb
T:1
M:1
T:2
M:2
T:3
M:3
T:4
M:4
T:5
M:5
T:6
M:6
T:7
M:7
T:8
M:8
T:9
M:9
T:10
M:10

C:\ScriptBASIC\examples>


John:


IUP is a cross platform GUI library that is easy to use and well supported. The librrary includes form, canvas and image control features.

IUP Home Page

IUP Include

--- Code: Script BASIC ---MODULE Iup ' SystemDECLARE SUB ::Open ALIAS "PuiOpen" LIB "pui"DECLARE SUB ::Close ALIAS "PuiClose" LIB "pui"DECLARE SUB ::Version ALIAS "PuiVersion" LIB "pui"DECLARE SUB ::Load ALIAS "PuiLoad" LIB "pui"DECLARE SUB ::Loadbuffer ALIAS "PuiLoadbuffer" LIB "pui"DECLARE SUB ::SetLanguage ALIAS "PuiSetLanguage" LIB "pui"DECLARE SUB ::GetLanguage ALIAS "PuiGetLanguage" LIB "pui"' AttributeDECLARE SUB ::StoreAttribute ALIAS "PuiStoreAttribute" LIB "pui"DECLARE SUB ::StoreAttributeId ALIAS "PuiStoreAttributeId" LIB "pui"DECLARE SUB ::SetAttribute ALIAS "PuiSetAttribute" LIB "pui"DECLARE SUB ::SetAttributeId ALIAS "PuiSetAttributeId" LIB "pui"DECLARE SUB ::SetfAttribute ALIAS "PuiSetfAttribute" LIB "pui"DECLARE SUB ::SetfAttributeId ALIAS "PuiSetfAttributeId" LIB "pui"DECLARE SUB ::SetfAttributeId2 ALIAS "PuiSetfAttributeId2" LIB "pui"DECLARE SUB ::SetAttributes ALIAS "PuiSetAttributes" LIB "pui"DECLARE SUB ::ResetAttribute ALIAS "PuiResetAttribute" LIB "pui"DECLARE SUB ::SetAtt ALIAS "PuiSetAtt" LIB "pui"DECLARE SUB ::SetAttributeHandle ALIAS "PuiSetAttributeHandle" LIB "pui"DECLARE SUB ::GetAttributeHandle ALIAS "PuiGetAttributeHandle" LIB "pui"DECLARE SUB ::GetAttribute ALIAS "PuiGetAttribute" LIB "pui"DECLARE SUB ::GetAttributeId ALIAS "PuiGetAttributeId" LIB "pui"DECLARE SUB ::GetAllAttributes ALIAS "PuiGetAllAttributes" LIB "pui"DECLARE SUB ::GetAttributes ALIAS "PuiGetAttributes" LIB "pui"DECLARE SUB ::GetFloat ALIAS "PuiGetFloat" LIB "pui"DECLARE SUB ::GetFloatId ALIAS "PuiGetFloatId" LIB "pui"DECLARE SUB ::GetFloatId2 ALIAS "PuiGetFloatId2" LIB "pui"DECLARE SUB ::GetInt ALIAS "PuiGetInt" LIB "pui"DECLARE SUB ::GetInt2 ALIAS "PuiGetInt2" LIB "pui"DECLARE SUB ::GetIntInt ALIAS "PuiGetIntInt" LIB "pui"DECLARE SUB ::GetIntId ALIAS "PuiGetIntId" LIB "pui"DECLARE SUB ::GetIntId2 ALIAS "PuiGetIntId2" LIB "pui"DECLARE SUB ::StoreGlobal ALIAS "PuiStoreGlobal" LIB "pui"DECLARE SUB ::SetGlobal ALIAS "PuiSetGlobal" LIB "pui"DECLARE SUB ::GetGlobal ALIAS "PuiGetGlobal" LIB "pui"' EventsDECLARE SUB __GetEvent ALIAS "GetEvent" LIB "pui"DECLARE SUB __MainLoop ALIAS "PuiMainLoop" LIB "pui"DECLARE SUB ::MainLoopLevel ALIAS "PuiMainLoopLevel" LIB "pui"DECLARE SUB __LoopStep ALIAS "PuiLoopStep" LIB "pui"DECLARE SUB __LoopStepWait ALIAS "PuiLoopStepWait" LIB "pui"DECLARE SUB __ExitLoop ALIAS "PuiExitLoop" LIB "pui"DECLARE SUB ::Flush ALIAS "PuiFlush" LIB "pui"DECLARE SUB ::GetCallback ALIAS "PuiGetCallback" LIB "pui"DECLARE SUB __SetCallback ALIAS "PuiSetCallback" LIB "pui"DECLARE SUB ::SetCallbacks ALIAS "PuiSetCallbacks" LIB "pui"DECLARE SUB ::GetActionName ALIAS "PuiGetActionName" LIB "pui"DECLARE SUB ::SetFunction ALIAS "PuiSetFunction" LIB "pui"DECLARE SUB ::RecordInput ALIAS "PuiRecordInput" LIB "pui"DECLARE SUB ::PlayInput ALIAS "PuiPlayInput" LIB "pui"' LayoutDECLARE SUB ::Create ALIAS "PuiCreate" LIB "pui"DECLARE SUB ::Destroy ALIAS "PuiDestroy" LIB "pui"DECLARE SUB ::Map ALIAS "PuiMap" LIB "pui"DECLARE SUB ::Unmap ALIAS "PuiUnmap" LIB "pui"DECLARE SUB ::GetAllClasses ALIAS "PuiGetAllClasses" LIB "pui"DECLARE SUB ::GetClassName ALIAS "PuiGetClassName" LIB "pui"DECLARE SUB ::GetClassType ALIAS "PuiGetClassType" LIB "pui"DECLARE SUB ::ClassMatch ALIAS "PuiClassMatch" LIB "pui"DECLARE SUB ::GetClassAttributes ALIAS "PuiGetClassAttributes" LIB "pui"DECLARE SUB ::GetClassCallbacks ALIAS "PuiGetClassCallbacks" LIB "pui"DECLARE SUB ::SaveClassAttributes ALIAS "PuiSaveClassAttributes" LIB "pui"DECLARE SUB ::CopyClassAttributes ALIAS "PuiCopyClassAttributes" LIB "pui"DECLARE SUB ::SetClassDefaultAttribute ALIAS "PuiSetClassDefaultAttribute" LIB "pui"DECLARE SUB ::Fill ALIAS "PuiFill" LIB "pui"DECLARE SUB ::Hbox ALIAS "PuiHbox" LIB "pui"DECLARE SUB ::Vbox ALIAS "PuiVbox" LIB "pui"DECLARE SUB ::Zbox ALIAS "PuiZbox" LIB "pui"DECLARE SUB ::Radio ALIAS "PuiRadio" LIB "pui"DECLARE SUB ::Normalizer ALIAS "PuiNormalizer" LIB "pui"DECLARE SUB ::Cbox ALIAS "PuiCbox" LIB "pui"DECLARE SUB ::Sbox ALIAS "PuiSbox" LIB "pui"DECLARE SUB ::Split ALIAS "PuiSplit" LIB "pui"DECLARE SUB ::Append ALIAS "PuiAppend" LIB "pui"DECLARE SUB ::Detach ALIAS "PuiDetach" LIB "pui"DECLARE SUB ::Insert ALIAS "PuiInsert" LIB "pui"DECLARE SUB ::Reparent ALIAS "PuiReparent" LIB "pui"DECLARE SUB ::GetParent ALIAS "PuiGetParent" LIB "pui"DECLARE SUB ::GetChild ALIAS "PuiGetChild" LIB "pui"DECLARE SUB ::GetChildPos ALIAS "PuiGetChildPos" LIB "pui"DECLARE SUB ::GetChildCount ALIAS "PuiGetChildCount" LIB "pui"DECLARE SUB ::GetNextChild ALIAS "PuiGetNextChild" LIB "pui"DECLARE SUB ::GetBrother ALIAS "PuiGetBrother" LIB "pui"DECLARE SUB ::GetDialog ALIAS "PuiGetDialog" LIB "pui"DECLARE SUB ::GetDialogChild ALIAS "PuiGetDialogChild" LIB "pui"DECLARE SUB ::Refresh ALIAS "PuiRefresh" LIB "pui"DECLARE SUB ::RefreshChildren ALIAS "PuiRefreshChildren" LIB "pui"DECLARE SUB ::Update ALIAS "PuiUpdate" LIB "pui"DECLARE SUB ::UpdateChildren ALIAS "PuiUpdateChildren" LIB "pui"DECLARE SUB ::Redraw ALIAS "PuiRedraw" LIB "pui"DECLARE SUB ::ConvertXYToPos ALIAS "PuiConvertXYToPos" LIB "pui"' DialogDECLARE SUB ::Dialog ALIAS "PuiDialog" LIB "pui"DECLARE SUB ::Popup ALIAS "PuiPopup" LIB "pui"DECLARE SUB ::Show ALIAS "PuiShow" LIB "pui"DECLARE SUB ::ShowXY ALIAS "PuiShowXY" LIB "pui"DECLARE SUB ::Hide ALIAS "PuiHide" LIB "pui"DECLARE SUB ::FileDlg ALIAS "PuiFileDlg" LIB "pui"DECLARE SUB ::MessageDlg ALIAS "PuiMessageDlg" LIB "pui"DECLARE SUB ::ColorDlg ALIAS "PuiColorDlg" LIB "pui"DECLARE SUB ::FontDlg ALIAS "PuiFontDlg" LIB "pui"DECLARE SUB ::Alarm ALIAS "PuiAlarm" LIB "pui"DECLARE SUB ::GetFile ALIAS "PuiGetFile" LIB "pui"DECLARE SUB ::GetColor ALIAS "PuiGetColor" LIB "pui"DECLARE SUB ::GetParam ALIAS "PuiGetParam" LIB "pui"DECLARE SUB ::GetText ALIAS "PuiGetText" LIB "pui"DECLARE SUB ::ListDialog ALIAS "PuiListDialog" LIB "pui"DECLARE SUB ::Message ALIAS "PuiMessage" LIB "pui"DECLARE SUB ::LayoutDialog ALIAS "PuiLayoutDialog" LIB "pui"DECLARE SUB ::ElementPropertiesDialog ALIAS "PuiElementPropertiesDialog" LIB "pui"' ControlsDECLARE SUB ::Button ALIAS "PuiButton" LIB "pui"DECLARE SUB ::Canvas ALIAS "PuiCanvas" LIB "pui"DECLARE SUB ::Frame ALIAS "PuiFrame" LIB "pui"DECLARE SUB ::Label ALIAS "PuiLabel" LIB "pui"DECLARE SUB ::List ALIAS "PuiList" LIB "pui"DECLARE SUB ::MultiLine ALIAS "PuiMultiLine" LIB "pui"DECLARE SUB ::ProgressBar ALIAS "PuiProgressBar" LIB "pui"DECLARE SUB ::Spin ALIAS "PuiSpin" LIB "pui"DECLARE SUB ::Tabs ALIAS "PuiTabs" LIB "pui"DECLARE SUB ::Tabsv ALIAS "PuiTabsv" LIB "pui"DECLARE SUB ::Text ALIAS "PuiText" LIB "pui"DECLARE SUB ::Toggle ALIAS "PuiToggle" LIB "pui"DECLARE SUB ::Tree ALIAS "PuiTree" LIB "pui"DECLARE SUB ::Val ALIAS "PuiVal" LIB "pui"DECLARE SUB ::Cells ALIAS "PuiCells" LIB "pui"DECLARE SUB ::Colorbar ALIAS "PuiColorbar" LIB "pui"DECLARE SUB ::ColorBrowser ALIAS "PuiColorBrowser" LIB "pui"DECLARE SUB ::Dial ALIAS "PuiDial" LIB "pui"DECLARE SUB ::Matrix ALIAS "PuiMatrix" LIB "pui"DECLARE SUB ::GLCanvas ALIAS "PuiGLCanvas" LIB "pui"DECLARE SUB ::PPlot ALIAS "PuiPPlot" LIB "pui"DECLARE SUB ::WebBrowser ALIAS "PuiWebBrowser" LIB "pui"' ResourcesDECLARE SUB ::Image ALIAS "PuiImage" LIB "pui"DECLARE SUB ::ImageRGB ALIAS "PuiImageRGB" LIB "pui"DECLARE SUB ::ImageRGBA ALIAS "PuiImageRGBA" LIB "pui"DECLARE SUB ::ImageLibOpen ALIAS "PuiImageLibOpen" LIB "pui"DECLARE SUB ::LoadImage ALIAS "PuiLoadImage" LIB "pui"DECLARE SUB ::SaveImage ALIAS "PuiSaveImage" LIB "pui"DECLARE SUB ::NextField ALIAS "PuiNextField" LIB "pui"DECLARE SUB ::PreviousField ALIAS "PuiPreviousField" LIB "pui"DECLARE SUB ::GetFocus ALIAS "PuiGetFocus" LIB "pui"DECLARE SUB ::SetFocus ALIAS "PuiSetFocus" LIB "pui"DECLARE SUB ::Item ALIAS "PuiItem" LIB "pui"DECLARE SUB ::Menu ALIAS "PuiMenu" LIB "pui"DECLARE SUB ::Menuv ALIAS "PuiMenuv" LIB "pui"DECLARE SUB ::Separator ALIAS "PuiSeparator" LIB "pui"DECLARE SUB ::Submenu ALIAS "PuiSubmenu" LIB "pui"DECLARE SUB ::SetHandle ALIAS "PuiSetHandle" LIB "pui"DECLARE SUB ::GetHandle ALIAS "PuiGetHandle" LIB "pui"DECLARE SUB ::GetName ALIAS "PuiGetName" LIB "pui"DECLARE SUB ::GetAllNames ALIAS "PuiGetAllNames" LIB "pui"DECLARE SUB ::GetAllDialogs ALIAS "PuiGetAllDialogs" LIB "pui"DECLARE SUB ::Clipboard ALIAS "PuiClipboard" LIB "pui"DECLARE SUB ::Timer ALIAS "PuiTimer" LIB "pui"DECLARE SUB ::User ALIAS "PuiUser" LIB "pui"DECLARE SUB ::Help ALIAS "PuiHelp" LIB "pui"' DECLARE SUB ::GetListText ALIAS "PuiGetListText" LIB "pui"' DECLARE SUB ::ClearList ALIAS "PuiClearList" LIB "pui" ' Helper FunctionsDECLARE SUB ::GetListText ALIAS "PuiGetListText" LIB "pui"DECLARE SUB ::GetBtnPressed ALIAS "PuiGetBtnPressed" LIB "pui"DECLARE SUB ::GetBtnState ALIAS "PuiGetBtnState" LIB "pui"DECLARE SUB ::ClearList ALIAS "PuiClearList" LIB "pui"DECLARE SUB ::Info ALIAS "PuiInfo" LIB "pui"  SUB MainLoopExitLoop = 0REPEAT  __LoopStepWait()  this_event = __GetEvent()  IF this_event <> undef THEN    IF this_event = event{this_event}[0] THEN      ICALL(event{this_event}[1])    END IF  END IFUNTIL ExitLoopEND SUB  FUNCTION SetCallback(ih, aname, faddr)  event{ih}[0] = ih  event{ih}[1] = faddr  event{ih}[2] = aname  SetCallback = __SetCallback(ih, aname)END FUNCTION END MODULE 

The following example is an online dictionary using IUP for the GUI and ScriptBasic to provided the data from the online dictionary API site.


--- Code: Script BASIC ---' IUP Online Dictionary IMPORT iup.sbi servers[0]="dict.org"servers[1]="dict1.us.dict.org"servers[2]="all.dict.org" about="IUP ScriptBasic Binding" ' Initialize IUPIup::Open() ' Create main window win = Iup::Create("dialog")  Iup::SetAttributes(win, "TITLE=\"ScriptBasic IUP Online Dictionary\", SIZE=500x300")  Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit())) ' Create container to house ALL GUI objects vbox = Iup::Create("vbox")  Iup::SetAttributes(vbox, "MARGIN=10x10") ' Create server panel topBox = Iup::Create("hbox")  Iup::SetAttributes(topBox, "GAP=10")  Iup::Append(vbox, topBox)serverFrame = Iup::Create("frame")  Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")  Iup::Append(topBox, serverFrame)serverBox = Iup::Create("hbox")  Iup::SetAttributes(serverBox, "GAP=5")  Iup::Append(serverFrame, serverBox)serverCombo = Iup::Create("list")  Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")  Iup::Append(serverBox, serverCombo)  Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))btnFetch = Iup::Create("button")  Iup::SetAttributes(btnFetch, "TITLE=Fetch, SIZE = 50x")  Iup::Append(serverBox, btnFetch)  Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked())) ' Create control panel controlFrame = Iup::Create("frame")  Iup::SetAttributes(controlFrame, "TITLE=Controls")  Iup::Append(topBox, controlFrame)controlBox = Iup::Create("hbox")  Iup::SetAttributes(controlBox, "GAP=5")  Iup::Append(controlFrame, controlBox)btnAbout = Iup::Create("button")  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")  Iup::Append(controlBox, btnAbout)  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))btnClear = Iup::Create("button")  Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")  Iup::Append(controlBox, btnClear)  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))btnExit = Iup::Create("button")  Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")  Iup::Append(controlBox, btnExit)  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit())) ' Create dictionary panel dictFrame = Iup::Create("frame")  Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")  Iup::Append(vbox, dictFrame)serverList = Iup::Create("list")  Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")  Iup::Append(dictFrame, serverList)  Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected())) ' Create text part transFrame = IUP::Create("frame")  Iup::SetAttributes(transFrame, "TITLE=Translation")  Iup::Append(vbox, transFrame)text = Iup::Create("text")  Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")  Iup::Append(transFrame, text) ' Create entry and search button bottomBox = Iup::Create("hbox")  Iup::SetAttributes(bottomBox, "GAP=10")  Iup::Append(vbox, bottomBox)label = Iup::Create("label")  Iup::SetAttributes(label, "TITLE=\"Enter Word to Search For:\", SIZE=x12")  Iup::Append(bottomBox, label)entry = Iup::Create("text")  Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")  Iup::Append(bottomBox, entry)btnSearch = Iup::Create("button")  Iup::SetAttributes(btnSearch,"TITLE=Search, SIZE=50x")  Iup::Append(bottomBox, btnSearch)  Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))chkAll = Iup::Create("toggle")  Iup::SetAttributes(chkAll, "TITLE=ALL, SIZE=x12")  Iup::Append(bottomBox, chkAll)chkUTF = Iup::Create("toggle")  Iup::SetAttributes(chkUTF, "TITLE=UTF-8, SIZE=x12")  Iup::Append(bottomBox, chkUTF) ' Add the main GUI container to the Window Iup::Append(win, vbox) ' Setup dialog defaults Iup::Show(win)Iup::SetFocus(btnFetch)FOR i = 0 TO UBOUND(servers)  Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])NEXTIup::SetAttribute(serverCombo, "VALUE", "1")Iup::Update(serverCombo)server_selection = servers[0] ' Main processing loop Iup::MainLoop()Iup::Close()END ' Callback routines SUB Win_exit  Iup::ExitLoop = TRUEEND SUB SUB btnAbout_clicked  Iup::Message("ABOUT", about)END SUB SUB serverCombo_selected  server_selection = Iup::GetListText()END SUB SUB serverList_selected  whichDictionary = Iup::GetListText()END SUB SUB btnFetch_clicked  LOCAL dat, total, count  ON ERROR GOTO G_NetError  OPEN server_selection & ":2628" FOR SOCKET AS #1  PRINT#1,"SHOW DB\n"  LINE INPUT#1, dat  LINE INPUT#1, dat  count = 0  WHILE LEFT(dat, 1) <> "."    LINE INPUT#1, dat    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)    count+=1  WEND  PRINT#1,"QUIT\n"  CLOSE(#1)  FOR cnt = 0 TO count - 2    Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])  NEXT  Iup::SetAttribute(serverList, "VALUE", "1")  Iup::Update(serverCombo)  whichDictionary = total[0]  EXIT SUB   G_NetError:  PRINT "Server ",server_selection," not available. (",ERROR,")\n"END SUB SUB btnClear_clicked  Iup::ClearList(serverList)  Iup::SetAttribute(text, "VALUE", "")  Iup::SetAttribute(entry, "VALUE", "")END SUB SUB btnSearch_clicked  LOCAL dict, dat, total, info  IUP::SetAttribute(text, "VALUE","Fetching....")  ON ERROR GOTO L_NetError  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))  OPEN server_selection & ":2628" FOR SOCKET AS 1  IF Iup::GetAttribute(chkAll, "VALUE") THEN    PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"  ELSE    PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"  END IF  REPEAT    LINE INPUT#1, dat    IF LEFT(dat, 3) = "151" THEN      total$ &= "------------------------------\r\n"      total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))      total$ &= "------------------------------\r\n"      REPEAT        LINE INPUT#1, info        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"      UNTIL LEFT(info, 1) = "."      total &= "\n"    END IF  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499  PRINT#1,"QUIT\n"  CLOSE(#1)  IF LEFT(dat, 3) = "552" THEN    total = "No match found."  ELSE IF LEFT(dat, 3) = "501" THEN    total = "Select a dictionary first!"  ELSE IF LEFT(dat, 3) = "550" THEN    total = "Invalid database!"  END IF  Iup::SetAttribute(text, "VALUE", total)EXIT SUB L_NetError:  dat[0] = "Could not lookup word! (" & ERROR & ")"  Iup::SetAttribute(text, "VALUE", dat)END SUB 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version