What it boils down to is one per cent inspiration and ninety-nine per cent perspiration.
Also i like your gifs

Again thanks, i'm so happy to know someone else of me like this merveillous little numerical moviesBitblazer wrote:Also i like your gifs
All the codes of SROD, is like amazing OYSTERS, i know they are a good thing to eat inside, and again better... know, they are obviously splendids pearls inside tooFangbeast wrote:I never understand srod either
Kwai chang caine wrote:
In the 'Demos' folder there are a couple of .pb test programs (IntegerArithmetic.pb is one such) amongst all of the test scripts (text files) that show how to call a simple script. The qdMin test editor is a more involved example of integrating minScript - though one with a somewhat limited 'brief'.Kiffi wrote:Hello srod,
i declare my solidarity with kcc. I don't know either how such an integration should take place.
So it would be very nice if you could post a small Hello-World example how to use minScript from PB.
Thanks in advance & Greetings ... Peter
My bad, I completely overlooked the PB files.srod wrote:In the 'Demos' folder there are a couple of .pb test programs (AddIntegers.pb is one such) amongst all of the test scripts (text files) that show how to call a simple script.
Code: Select all
#minScript_HOME = "E:\User\HeX0R\Documents\Sources\PureBasic\minScript\Source\" ;<- change!
XIncludeFile #minScript_HOME + "minScript.pbi"
;the init is already running there, so we'll check if it went smoothly
If minScriptINIT <> #minScript_OKAY
Debug "something went wron..."
End
EndIf
Structure _MyCodeObject_
myCode.minScriptCode ;<- Code Objekt
*returnVar.minScriptVariant ;<- return pointer, if you call a minScript function with PB, the return value is written in it
EndStructure
Global mS._MyCodeObject_
;Host function, called by minscript
Procedure mystrd(codeObject.minScriptCode, fnID.l, numParamsPassed, *params.minScriptVariantParameters, *ret.minScriptVariant)
Protected i, Var.s, *Sp.STRING, d.d, result = #minScript_OKAY
;codeObject is here the same as mS\myCode
;fnID is a unique index describing the function, you define it when loading.
;numParamsPassed is the number of parameters you get.
;You can react here to completely different number of parameters accordingly.
;params is an array with the parameters that the function got
;you can use *ret to send something back to the script.
If numParamsPassed = 1 ;
;to be on the safe side, we'll make sure we have a string.
If minScript_VarChangeType(*Params\index[0], #minScript_String) = #minScript_OKAY
*Sp = *params\index[0]
Var = *Sp\s
EndIf
d = ValD(Var)
;now we set the return value for the script
;In contrast to LUA, you can only use a maximum of ONE return value!
minScript_VarSetReal(*ret, d)
Else
result = #minScript_INCORRECTNUMBEROFPARAMETERS
EndIf
ProcedureReturn result
EndProcedure
;Initialize our mS structure
mS\myCode = minScript_NewCodeObject()
If mS\myCode = 0
Debug "can't create aCodeObject!"
End
EndIf
;and get us the global return pointer
mS\returnVar = mS\myCode\GetReturnVariantPtr()
;now we introduce the script with our host function
;important! They must be created BEFORE the code is loaded!
minScript_AddRuntimeFunction("mystrd", 1, @mystrd()) ;<-Runtime functions are valid for all modules!
;If you don't want to do this, you must initialize a new CodeObject.
;Then everything is encapsulated
;The 1 is a numeric number that describes this function uniquely and is also passed in the host application (as fnID)
;So the next one would have a 2,3, or even 10,30,....
;o.k., we're ready!
;You can load whole scripts with the PB file-commands, put the whole thing together to a big string and then load it, we'll make it easier and use a string.
SCRIPT.s = "function multi(a as real, b as real)" + #CRLF$ +
" Dim result as real ;no need for a local variable, but we use it here!" + #CRLF$ +
" result = a * b" + #CRLF$ +
" return result" + #CRLF$ +
"endfunction" + #CRLF$
;in the next function we use a host (PB) function (minscript doesn't know mystrd())
SCRIPT + "function bla()" + #CRLF$ +
" Dim result as real" + #CRLF$ +
" result = mystrd(" + #DQUOTE$ + "1.25E-3" + #DQUOTE$ + ")" + #CRLF$ +
" return result" + #CRLF$ +
"endfunction"
;Now let's load this into a module, you can load several modules, call the calls by module name:FunctionName() to explicitly use the function of a module.
If mS\myCode\AddModule("HansWurst", @SCRIPT) <> #minScript_OKAY
;we got some mistakes in there, let's take a look at them:
Debug " Error code : " + Str(mS\myCode\GetLastErrorCode())
Debug " Error line number : " + Str(mS\myCode\GetLastErrorLineNumber())
Debug " Source line : " + mS\myCode\GetLastCompilationErrorLine()
End
EndIf
;All right, this thing's loaded now.
;Now we're ready.
;First test, we let minScript calculate for us.
If mS\myCode\Execute("return HansWurst:multi(3, 5)") <> #minScript_OKAY
;oha, another mistake, check it out
Debug " Error code : " + Str(mS\myCode\GetLastErrorCode())
Debug " Error source line number : " + Str(mS\myCode\GetLastErrorLineNumber())
Debug " Error function name : " + mS\myCode\GetLastExecutionErrorFunctionName()
Debug " (If 'Error function name' is NULL then the error occurred within the \Execute() method call.)"
Else
;has worked out, let's have a look at the result, we just want a real one anyway, so
If minScript_VarChangeType(mS\returnVar, #minScript_REAL) = #minScript_Okay
Debug minScript_VarGetReal(mS\returnVar)
EndIf
EndIf
;Second part, we call our PB function
If mS\myCode\Execute("return HansWurst:bla()") <> #minScript_OKAY
;oha, another mistake, check it out
Debug " Error code : " + Str(mS\myCode\GetLastErrorCode())
Debug " Error source line number : " + Str(mS\myCode\GetLastErrorLineNumber())
Debug " Error function name : " + mS\myCode\GetLastExecutionErrorFunctionName()
Debug " (If 'Error function name' is NULL then the error occurred within the \Execute() method call.)"
Else
;anything fine, let's have a look at the result, we have a real one again.
;(minScript uses variants, if you are sure that you got a real one, you can give yourself a lot of stuff here and access mS\returnVar\r directly)
If minScript_VarChangeType(mS\returnVar, #minScript_REAL) = #minScript_Okay
Debug minScript_VarGetReal(mS\returnVar)
EndIf
EndIf
No.HeX0R wrote: Tipp:
I would scan minScript.pbi, minScriptVariants.pbi and minScriptMAIN.pbi to be able to use auto complete functionality of the IDE. (@Stephen: didn't you say you will change this?)
All run-time functions are global in that any module in any code object within the host application has access to each and every function. You can't hide them!HeX0R wrote:I think my remark regarding minScript_AddRuntimeFunction is wrong. As long as there is no possibility to send a codeobject to the function, the runtime functions will still be global, even across different codeobjects.
Or am I wrong?
O.k., I thought I'd read that this has changed (/improved?).srod wrote:All run-time functions are global in that any module in any code object within the host application has access to each and every function. You can't hide them!
Code: Select all
;PSPad user HighLighter definition file
[Settings]
Name=minScript
HTMLGroup=0
Vectors=0
Label=1
FileType=*.script,*.tscript
CommentString=
BasComment=1
IndentChar=
UnIndentChar=
TabWidth=0
DoubleQuote=1
EscString=1
EscChar=\
KeyWordChars=_
CodeExplorer=ftUnknown
DocComment=
[KeyWords]
and=
as=
case=
currency=
debug=
default=
dim=
integer=
let=
method=
or=
private=
property=
real=
return=
step=
string=
stringbuilder=
variant=
xor=
[ReservedWords]
break=
else=
elseif=
class=
endclass=
endfunction=
endif=
endmethod=
endselect=
for=
function=
if=
next=
repeat=
select=
until=
wend=
while=
[KeyWords2]
and=
array=
as=
debug=
integer=
real=
string=
table=
tocurrency=
tointeger=
toreal=
tostring=
[KeyWords3]
allocatememory=
asc=
chr=
freememory=
isclass=
isfunction=
isobject=
isruntimefunction=
lcase=
left=
len=
mid=
nothing=
peekb=
peekc=
peekcurrency=
peekf=
peeki=
peekl=
peekr=
peeks=
peekw=
pokeb=
pokec=
pokecurrency=
pokef=
pokei=
pokel=
poker=
pokes=
pokew=
reallocatememory=
right=
sizeof=
space=
str=
strfix=
stringbytelength=
throwerror=
trim=
truncate=
typeof=
typeof2string=
ucase=
stringfield=