squirrel
Squirrel 是一个高水平,面向对象的编程语言,是为一定大小,内存带宽和有实时需求应用(比如视频游戏)而设计的一款轻量级脚本语言。
Squirrel 主要特性:
开源,遵循 MIT licence 开源授权
动态输入
委托
类 & 继承
更高级的排序函数
词法作用域
生成器
合作线程(协同程序)
尾递归
异常处理
自动内存管理 (CPU bursts free; mixed approach ref counting/GC)
使用 7k 行的 C++ 代码就结合了编译器和虚拟机,添加了 100kb-150kb 的可执行大小
可选 16bits 字符字符串
强大的可潜入 API
eg. function/classes can be defined by scripts or in C
eg. objects can fully exist in the VM or be bound to native code
eg. classes created in C can be extended by scripts or vice-versa
等等
Squirrel 灵感来源于 Python,JavaScript 和 Java。
Squirrel 支持 Windows(x86 & x64), Linux(x86 & x64), Illumos(x86 & x64), Mac OS X, FreeBSD, iOS 和 Android 平台。
Squirrel 支持的编译器:
MS Visual C++ 6.0,7.0,7.1,8.0,9.0 and 10.0(x86 & x64)
MinGW gcc 3.2 (mingw special 20020817-1)
Cygwin gcc 3.2
Linux gcc 3.x
Linux gcc 4.x
Illumos gcc 4.x
XCode 4
示例
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)
{base.constructor("Player",entityname)
}function DoDomething()
{
::print("something");
}
}
local newplayer = Player("da playar");
newplayer.MoveTo(100,200,300);
微信订阅号:开源派 (opensourcepie)
开源派官网:osp.io 作者:叶秀兰