Well ive been floating around these forums for ages, but never posted any of my work, so i might as well now.
This is a basic wrapper for the squirrel scripting languages, if you dont know what squirrel is you can get infomation on it here - http://squirrel-lang.org/
Ive also posted some examples lower in this post.
You can download the module here - www.savefile.com/files/6495778
It now contains a few examples to show things like precompilations and parameter masking, it also contains a type called TSquirrelEngine to make using squirrel a LOT easier, as it handles all the complex stack routines for you. Theres still a lot of things to implement though such as classes, arrays and such, but there coming along :).
Anyway enjoy, hope thats helpfull.
BlitzMax Code:
Squirrel Code:
This is a basic wrapper for the squirrel scripting languages, if you dont know what squirrel is you can get infomation on it here - http://squirrel-lang.org/
Ive also posted some examples lower in this post.
You can download the module here - www.savefile.com/files/6495778
It now contains a few examples to show things like precompilations and parameter masking, it also contains a type called TSquirrelEngine to make using squirrel a LOT easier, as it handles all the complex stack routines for you. Theres still a lot of things to implement though such as classes, arrays and such, but there coming along :).
Anyway enjoy, hope thats helpfull.
BlitzMax Code:
Rem Squirrel - Example 4 : Precompiling This shows how to precompile a script Created by Tim Leonard (Aka. Helios) Version 1.0 End Rem Rem Framework End Rem Strict Framework BRL.System Import BRL.retro Import DE.Squirrel Rem Squirrel Example End Rem ' Create a new squirrelengine Global SE:TSquirrelEngine = New TSquirrelEngine ' Load the test file SE.LoadFile("Scripts\Example4.nut") ' Now lets dump the compile bytecode to a file SE.DumpByteCode("Scripts\Example4.cnut") ' Kill Old Squirrel Engine SE = Null FlushMem() ' Now to show that this has dumped the file ' succcesfully, we will create another squirrel engine ' and make it run it ' Create new engine SE:TSquirrelEngine = New TSquirrelEngine ' Register a simple function with ' a parameter mask and count SE.RegisterGlobalFunction(func_Notify,"Notify",2,"sn") ' Now lets test if it reads out byte code ' successfully, it will auromatically decide ' if the file is compiled or not and load it ' appropriatly, you shhould notice a loading dip of about ' 10ms for a simple script when you precompile SE.LoadFile("Scripts\Example4.cnut") Se.Run() Rem Our squirrel function, must always have the prototype of FunctionName(State:Byte ptr) This is called with 2 paremeters the first being a string and the second being a integer End Rem Function Func_Notify(State:Byte Ptr) ' Please not that when accessing paremeters ' always start at 0 as the TSquirrelEngine access ' them as zero-based Notify SE.GetStringParameter(0),SE.GetIntegerParameter(1) End Function
Squirrel Code:
local table = { a = "10" subtable = { array = [1,2,3] }, [10 + 123] = "expression index" } local array=[ 1, 2, 3, { a = 10, b = "string" } ]; foreach (i,val in array) { ::print("the type of val is"+typeof val); } ///////////////////////////////////////////// class Entity { constructor(etype,entityname) { name = entityname; type = etype; } x = 0; y = 0; z = 0; name = null; type = null; } function Entity::MoveTo(newx,newy,newz) { x = newx; y = newy; z = newz; } class Player extends Entity { constructor(entityname) { Entity.constructor("Player",entityname) } function DoDomething() { ::print("something"); } } local newplayer = Player("da playar"); newplayer.MoveTo(100,200,300);