DracScript 1.06 Released! LGPL Scripting Language

Developed or developing a new product in PureBasic? Tell the world about it.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

enableexplicit gets very annoying in a scripting language most of the time, but its easy enough for you to add if you want. just be sure to post your modified version of the source here.
Netvampire
New User
New User
Posts: 7
Joined: Fri Dec 29, 2006 6:52 pm
Location: Germany

Post by Netvampire »

Very Nice! Thank you!
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

You're welcome. If you use it I'd love to see the program you used it in when its done.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

dracflamloc: Just a quick note to let you know I'll be using DracScript in "Elementary Reports". I'm building it in from the beginning so it should be good. :)
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Great, be sure to let me know if you add anything or need some pointers.

My MMORPG currently has over 400 scripts being run constantly as people play so its quite robust.
Godai
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Oct 05, 2006 8:13 pm

Problem with DracScript

Post by Godai »

I tried DracScript out and there really should be a PB example, as it was some search getting everything up and running, grabbing parms from the stack, guessing that strings should have '' around them etc.

Also, this does not work (AddObject is my function)

Code: Select all

i = 0
while i < 10
AddObject('testobjectname', i, 10, 20)
wend
It only calls the object once. Am I doing something wrong?
Thanks in advance
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

For one you never increment i in your while loop. You need i=i+1 in there.

There is an example at the end of DracScript.pb in a CompilerIf. Please check that out as it should be quite helpful for you.

Also I believe I changed the character that signifies strings to double-quote ( " )
Godai
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Oct 05, 2006 8:13 pm

Post by Godai »

Problem solved. Remember to tell people that they need to return a value from the procedures or it will halt the entire script with a command error (which is silent unless you check for it ;))

Also, a function to convert error codes to strings would rock too!
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

This is the DS editor I posted in another thread, but I figured I should move it here so more people find it:

Code: Select all

#DS_EDITOR_KEYWORDS = " if else elseif endif exit free while wend goto label "
#DS_EDITOR_OPENFOLD = " while if "
#DS_EDITOR_CLOSEFOLD = " wend endif "
#DS_EDITOR_ENDCONSTANT = "+=-*/%$ !<>|\/.,()"

Enumeration 0
    #LexerState_Space
    #LexerState_Comment
    #LexerState_NonKeyword
    #LexerState_Keyword
    #LexerState_FoldKeyword
    #LexerState_Constant
    #LexerState_String
EndEnumeration

Procedure.l Scintilla(sciptr.l, p1.l, p2.l=0, p3.l=0)
  ProcedureReturn ScintillaSendMessage(sciptr,p1,p2,p3)
EndProcedure

Procedure Highlight(sciptr.l, startpos.l, endpos.l)
    Debug(sciptr)
    If startpos = -1
        endstyled.l = Scintilla(sciptr, #SCI_GETENDSTYLED)
        linenumber.l = Scintilla(sciptr, #SCI_LINEFROMPOSITION, endstyled)
    Else
        linenumber = Scintilla(sciptr, #SCI_LINEFROMPOSITION, startpos)
    EndIf
   
    If linenumber = 0
        level = #SC_FOLDLEVELBASE
    Else
        linenumber - 1
        level = Scintilla(sciptr, #SCI_GETFOLDLEVEL, linenumber) & ~ #SC_FOLDLEVELHEADERFLAG
    EndIf
   
    thislevel.l = level
    nextlevel.l = level
   
    currentpos.l = Scintilla(sciptr, #SCI_POSITIONFROMLINE, linenumber)
    Scintilla(sciptr, #SCI_STARTSTYLING, currentpos, $1f | #INDICS_MASK)
    state = #LexerState_Space
    startkeyword = currentpos
    keyword.s = ""
   
    qpos.l = -1 ;quote pos
    While currentpos <= endpos
        oldstate = state
        lastchar.l = char.l       
        char.l = Scintilla(sciptr, #SCI_GETCHARAT, currentpos)
        If char = ';'
            state = #LexerState_Comment
        ElseIf char = '"' And state<>#LexerState_String And state<>#LexerState_Comment
            state = #LexerState_String
            qpos = currentpos
        ElseIf state = #LexerState_String
            If (qpos<>currentpos-1 And lastchar = '"') Or char = 10 Or char = 13
              state=#LexerState_Space
              qpos=-1
            EndIf         
        ElseIf char = 10 Or char = 13
            state = #LexerState_Space
        ElseIf state <> #LexerState_Comment
            If state=#LexerState_Constant
              If FindString(#DS_EDITOR_ENDCONSTANT,Chr(char),1) Or char=10 Or char=13 Or char=9
                state=#LexerState_Space
              EndIf
            Else             
              If char='#'
                  state = #LexerState_Constant               
              ElseIf char = 9 Or char = ' ' Or char = '.'
                  state = #LexerState_Space
              Else
                  state = #LexerState_NonKeyword
                  keyword + Chr(char)
              EndIf
            EndIf
        EndIf
        If oldstate <> state Or currentpos = endpos
            If oldstate = #LexerState_NonKeyword
                lkeyword.s = LCase(keyword)
                If FindString(#DS_EDITOR_OPENFOLD," "+LCase(keyword)+" ",1)
                    thislevel | #SC_FOLDLEVELHEADERFLAG
                    nextlevel + 1
                ElseIf FindString(#DS_EDITOR_CLOSEFOLD," "+LCase(keyword)+" ",1)
                    nextlevel - 1
                    If nextlevel < #SC_FOLDLEVELBASE
                        nextlevel = #SC_FOLDLEVELBASE
                    EndIf
                EndIf
               
                If FindString(#DS_EDITOR_KEYWORDS," "+LCase(keyword)+" ",1)
                  oldstate = #LexerState_Keyword                                   
                EndIf               
               
                keyword = ""
            EndIf
            Scintilla(sciptr, #SCI_SETSTYLING, currentpos - startkeyword, oldstate)
            startkeyword = currentpos
        EndIf
       
        If char = 10 Or currentpos = endpos
            Scintilla(sciptr, #SCI_SETFOLDLEVEL, linenumber, thislevel)
            thislevel = nextlevel
            linenumber + 1
        EndIf
       
        currentpos + 1
    Wend
EndProcedure

ProcedureDLL ScCallBack(EditorGadget.l, *scinotify.SCNotification)
  If *scinotify\nmhdr\code = #SCN_STYLENEEDED
    Highlight(1, -1, *scinotify\position)
  ElseIf *scinotify\nmhdr\code = #SCN_MARGINCLICK
    modifiers = *scinotify\modifiers
    position = *scinotify\position
    margin = *scinotify\margin
    linenumber = Scintilla(1, #SCI_LINEFROMPOSITION, position)
    Select margin
        Case 2
            Scintilla(1, #SCI_TOGGLEFOLD, linenumber)
    EndSelect
  EndIf
EndProcedure

OpenWindow(0,0,0,600,600,"")

RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab | #PB_Shortcut_Shift)

InitScintilla("Scintilla.dll")
CreateGadgetList(WindowID(0))
ScintillaGadget(1,0,0,600,500,@ScCallBack())
ButtonGadget(2,0,510,100,50,"GetText")

; Margins
Scintilla(1, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 10)
Scintilla(1, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
Scintilla(1, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
Scintilla(1, #SCI_SETMARGINWIDTHN, 0, 34)
Scintilla(1, #SCI_SETMARGINWIDTHN, 1, 1)
Scintilla(1, #SCI_SETMARGINWIDTHN, 2, 15)
Scintilla(1, #SCI_SETMARGINSENSITIVEN, 2, #True)

; Choose folding icons
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_CIRCLEMINUS)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER, #SC_MARK_CIRCLEPLUS)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB, #SC_MARK_VLINE)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL, #SC_MARK_LCORNERCURVE)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND, #SC_MARK_CIRCLEPLUSCONNECTED)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID, #SC_MARK_CIRCLEMINUSCONNECTED)
Scintilla(1, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERMIDTAIL, #SC_MARK_TCORNERCURVE)

; Choose folding icon colours
Scintilla(1, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, $FFFFFF)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, 0)
Scintilla(1, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, $FFFFFF)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, 0)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, 0)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERSUB, 0)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERTAIL, 0)
Scintilla(1, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERMIDTAIL, 0)

;lex setup
ScintillaSendMessage(1,#SCI_SETLEXER, #SCLEX_CONTAINER, 0);
ScintillaSendMessage(1,#SCI_STYLESETFORE, #STYLE_DEFAULT, RGB(0,0,0));
ScintillaSendMessage(1,#SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(255,255,255));
ScintillaSendMessage(1,#SCI_STYLECLEARALL);

; Set caret line colour
ScintillaSendMessage(1, #SCI_SETCARETLINEBACK, RGB(231, 245, 255))
ScintillaSendMessage(1, #SCI_SETCARETLINEVISIBLE, #True)

; Set styles for custom lexer
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_Comment, $8800)
ScintillaSendMessage(1, #SCI_STYLESETITALIC, #LexerState_Comment, 1)
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_NonKeyword, 0)
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_Keyword, 0)
ScintillaSendMessage(1, #SCI_STYLESETBOLD, #LexerState_NonKeyword, 0)
ScintillaSendMessage(1, #SCI_STYLESETBOLD, #LexerState_Keyword, 1)
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_FoldKeyword, $ff)
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_Constant, RGB(180,0,0))
ScintillaSendMessage(1, #SCI_STYLESETFORE, #LexerState_String, RGB(0,100,170))

SetGadgetText(1,";test comment"+#CRLF$+"If abc=1"+#CRLF$+"   Goto hi_there"+#CRLF$+"EndIf")

Repeat

 event=WaitWindowEvent()

 If event=#PB_Event_Gadget
   If EventGadget()=2
     MessageRequester("Get",GetGadgetText(1))
   EndIf
 EndIf

Until event=#PB_Event_CloseWindow
End 
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Can I have your permission intergrate this in an app that plays the scripts? :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Sure, as long as i get a copy =)
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

np :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

dracflamloc: I've PM'ed you a code for the program.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

How fast is this scripting language, compared to, say, Lua?.

:lol: should I bash the keyboard and give up?
:?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Why not include both this and lua?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply