New scripting engine - testers wanted!

Everything else that doesn't fall into one of the other PB categories.
User avatar
HeX0R
Addict
Addict
Posts: 979
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: New scripting engine - testers wanted!

Post by HeX0R »

I love this stringbuilder, this will come in quite handy!
Unfortunately it didn't help in my special case, but I feared that already, this slowness is coming from somewhere else.

I'm fine with the current state, quite powerful I must admit!
The only two things I had to add were a different toreal() function that can handle scientific notation and a stringfield() function.

Just one more question:
You have commented on FastToString as follows:
The FastToString() method is very fast, but renders the string builder instance unusable afterwards
What does that mean? I need to reinitialize the whole stringbuilder variable afterwards and all set strings are gone?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

Huh, I could have sworn I added a StringField() function! Doh! If you want I can add your version to minScript if you pm or email me the code.

Yes the .FastToString() method is a once only use. You can not add any strings to the underlying string builder after this - it is dead! This is because this method creates a string without copying any memory; it simply has the string point directly to the string builder object's buffer. Doesn't get any faster than that. :) You have to create another string builder object if you wish to continue with further string builder type operations. Use the .ToString() method if you want to serialize the string builder, but not destroy the builder in the process.

Incidentally, if you look in the specifications folder, the 'ConstantsAndStandardRuntime.txt' text file details not only all standard runtime functions, but also lists all user-defined types and their methods and properties. This includes the string builder type. Scroll down towards the bottom of the file.
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

:D Very useful. Thanks for sharing @srod.
QuimV
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

I need to make a small application that consists of the following tasks:

1: Declaration of 100 integer variables
2: Creation of boolean relationships between each 4 variables, for example: var5 = (var1 OR var2) AND (var3 OR var4)
3: Assignment of values to the variables declared in the 1st point
4: Reading of the result of each relationship created in the 2nd point
5: Repeat the 2nd and 3rd points indefinitely.

What is the best way to start building this application with minScript?

:D Thanks in advance
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

Hi QuimV,

yes declaring 100 individual integer variables would be inefficient in the extreme!

An integer array combined with a simple loop will surely get the job done. :)

The following simple script allows you to pass an existing integer array and then it runs through the elements and makes the kind of calculations you stated as I understand it (we are using logical OR/AND etc. as opposed to bitwise ops) :

Code: Select all

FUNCTION QuimV(myarray AS ARRAY)
  DIM i AS INTEGER
  IF myArray AND myArray.TypeOf = #INTEGER AND myArray.NumDims = 1
    FOR i = 5 TO myArray.UBound() STEP 5
      myArray(i) = (myArray(i-4) OR myArray(i-3)) AND (myArray(i-2) OR myArray(i-1)) 
    NEXT
  ENDIF
ENDFUNCTION
You could populate the array in a separate function or even in your host app (using minScript's as yet undocumented API!) etc.

Another alternative would be to allocate a chunk of memory (in script) the size of 100 integers and then use pointers to manipulate the individual integers etc.

Now, as to how you make use of minScript; you either do as HexOR and learn from the qdMin source and various other bits or await the documentation which is moving along. Should get a sizeable chunk of it done today. :)
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

Thanks srod for your quick response.
:oops: I have explained badly. In point 2, I wanted to say: "Creation of boolean relationships between N RANDOM VARIABLES DECLARED, for example: (var1 OR var10) AND (var30 OR var41)" that is, I must work with the name of the variables and obtain from PB the result of the Boolian relationship.
Thanks @srod
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

Not really sure what you mean?

It is not possible to create a persistent boolean relationship between variables in the same way you cannot do that in Purebasic and in the same way you cannot simply declare a persistent arithmetic relationship between variables (except in a spreadsheet for example). Such a relationship can only be evaluated at any given time in the form of an expression to be evaluated etc. and there is nothing stopping you doing that in Purebasic or minScript.

I don't really understand why you would need a scripting engine for this?

If I have the wrong end of the stick completely here then you will need to give me an example I can follow.

**EDIT : unless, are you talking about using minScript to effectively create boolean links between Purebasic variables? What I mean is, everytime you call this script, it evaluates all of these boolean relationships between the variables previously specified? I am probably wrong here as it would be easier just to use Purebasic for this!
I may look like a mule, but I'm not a complete ass.
User avatar
HeX0R
Addict
Addict
Posts: 979
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: New scripting engine - testers wanted!

Post by HeX0R »

Still no more bugs found, really good work!
And I finally found the "brake" in my code, minScript is indeed very fast!

One more question came up:
I probably need the possibility to send memory blocks to minScript to do some Peek action.
I tried to allocate memory in pb and send the pointer via an integer to minScript, but peeking doesn't seem to work (just did a very quick test).
How would I do that?
I don't want to change that memory block, just need to look into it.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

Yes, I'm talking about using minScript to effectively create boolean links between not Purebasic variables, I mean, the user creates the variables and the relationships between them and stores them in a line of a text file. Every second, the PureBasic program loads the text file and evaluates the result of each relationship, line by line, and saves the result and a timestamp in a database.

The other alternative I have is to use VBscript with COMatePLUS.
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

HeX0R wrote:Still no more bugs found, really good work!
And I finally found the "brake" in my code, minScript is indeed very fast!
:) Glad to hear that. My own tests show that minScript scripts can run very fast if you structure them properly.
HeX0R wrote:One more question came up:
I probably need the possibility to send memory blocks to minScript to do some Peek action.
I tried to allocate memory in pb and send the pointer via an integer to minScript, but peeking doesn't seem to work (just did a very quick test).
How would I do that?
I don't want to change that memory block, just need to look into it.
I just did a quick test and it worked absolutely fine. I created a memory block in PB, poked an integer within and then passed the address to a script. The script then returned the previously poked value. No problem. Use the various PEEK() standard runtime functions or use a pointer object etc. A pointer object would probably be quicker.

Here is some stripped down PB code which runs fine here. I have removed all error checking.

Code: Select all

#minScript_HOME = "c:/PurebasicCode/minScript/Source/"  

XIncludeFile #minScript_HOME + "minScript.pbi"
If minScriptINIT <> #minScript_OKAY
  Debug "minScript failed to initialize correctly."
  End
EndIf

;Our simple script function.
  code$ = "FUNCTION PEEKBUFFER(address AS INTEGER)" + #CRLF$
  code$ + "  RETURN PEEKI(address)" + #CR$ + #LF$
  code$ + "ENDFUNCTION"  + #CR$ + #LF$

;Create a minScriptCode object and check the return value.
  Define myCode.minScriptCode
  myCode = minScript_NewCodeObject()

  If myCode = 0 ;Typically a memory allocation issue.
    Debug "Could not create a code object!"
    End
  EndIf

;Submit our script function and check the return value.
  If myCode\AddModule("Module1", @code$) = #minScript_OKAY
    ;Obtain the address of our return values. This address is valid throughout the life of our minScriptCode object.
      *returnVar.minScriptVariant = myCode\GetReturnVariantPtr()
    ;Call the scripted function with the address of a suitable memory buffer.
      buffer = AllocateMemory(100)
      PokeI(buffer, 10)
      result = myCode\Execute("RETURN PEEKBUFFER(" + Str(buffer) + ")")
      FreeMemory(buffer)
    Debug "Result = " + Str(*returnVar\i)
  EndIf

;Release the minScriptCode object.
  myCode\Destroy()
minScript scripts work fine with PB code and variables. You can easily pass the address of a PB variable to a script and have the script then alter the variable etc.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

QuimV wrote:Yes, I'm talking about using minScript to effectively create boolean links between not Purebasic variables, I mean, the user creates the variables and the relationships between them and stores them in a line of a text file. Every second, the PureBasic program loads the text file and evaluates the result of each relationship, line by line, and saves the result and a timestamp in a database.

The other alternative I have is to use VBscript with COMatePLUS.
Yes that should be possible although loading the text file every second sounds a bit much!

If you can 'word' the relationships in terms of minScript code then you shouldn't have a problem doing that sort of thing. If you can do it with VBScript then you can do it with minScript.

minScript's standard runtime does not at this time include file or database functions, but then it can't include everything. You would need to add the appropriate runtime functions yourself which is pretty straightforward; an integral part of any scripting engine.
Having said that, adding runtime functions is easy in principal if the said functions do not create a potential for memory leaks. Having a OpenFile() type function, for example, is definitely one with this potential because if the script-writer then forgets to invoke a corresponding CloseFile() type function (or the script generates an error before the CloseFile() is called), then the file will remain open! minScript's garbage collector can do nothing about that.

An OpenFile() type run-time function is thus 'fiddly' because whoever creates this function needs to also create an 'extension' to our garbage collector to deal with any 'wayward' file handles and the like. We had to do something similar for our AllocateMemory() runtime function.

Probably best if I simply add some file functions to the standard runtime myself when I get the chance as I can easily create the necessary garbage collector extension (or just extend the existing AllocateMemory() one). Mind you, this problem would be removed if you created a run-time function which opens the file, reads the data and then closes the file before passing control back to the script. No possibilities of any file handles remaining open with this. The data read can then be shoved into a global script array or some such so that the script can work on the data.

A similar thing holds for any runtime function which opens a database etc. (unless the function closes the database before finishing!)

Yes, when I get a chance I will either add some file runtime functions or a file object as it is probably a feature which a lot of scripts will require.
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

:D Thank you very much for your advice.
By the way, two questions: is it possible to create static or global variables inside minScript? Can we access variables within a module from within a different module?
Thanks again
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: New scripting engine - testers wanted!

Post by srod »

QuimV wrote::D Thank you very much for your advice.
By the way, two questions: is it possible to create static or global variables inside minScript? Can we access variables within a module from within a different module?
Thanks again
minScript has the following types of variable in terms of scope.
  • Local variables
  • Module variables.
    These variables are global throughout a module in that any function/method within the same module can access them. They cannot be accessed from different modules.
  • Script variables.
    These are the top-level global variables and are accessible to all functions, methods and to all modules within the same code-object. They are even accessible to the host application.
So, no static variables because they are not needed. Just use a module or script variable prefixed with the function name etc. Only script variables are accessible to other modules; though they are not accessible to modules in other code-objects.

(A code object is the means through which you can add code modules etc. A host app can use as many different code objects as it wishes.)
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Re: New scripting engine - testers wanted!

Post by QuimV »

Could you gime me a very short example, Please?

Thanks in advanced.
QuimV
User avatar
HeX0R
Addict
Addict
Posts: 979
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: New scripting engine - testers wanted!

Post by HeX0R »

@QuimV

Code: Select all


;Module variables get declared OUTSIDE functions and will be globaly accessible within this module
Dim ModuleVariable as integer

function init()
  ;Script variables get prefixed with $
  ;you would not dim it within a function usualy, this is just to demonstrate, that it is accessible from ANYWHERE as long as it is within the same code object
  Dim $ScriptVar as string
  ModuleVariable = 12
  $ScriptVar = "What?"
endfunction

function test()
  ;local variables get declared INSIDE functions and are only accessible inside this function
  dim localVariable as integer

  init()
  ;we also have access to module variables
  debug(ModuleVariable)
  ;and of course also to script variables
  debug($ScriptVar)
endfunction
@Stephen:
You were right regarding memory blocks, it works flawlessly, seems I were drunk when I tested it (as usual) :)
Post Reply