关于选择脚本的问题

来源:互联网 发布:fft算法 c语言 编辑:程序博客网 时间:2024/05/19 00:42

  这几天在写一个游戏,使用delphi开发,引擎使用的是pxl,准备给游戏加入脚本功能,首先想到的是使用lua,但是自己能力和精力有限,对lua不是很了解,找了几个lua的库,都不是很理想,PLUA 这个库还是封装的不错的,但是不支持安卓, verysimplelua支持,但是他的调用方式让人受不了,不管什么都封装成函数, 先不说工作量,就是LUA脚本写出来,太别扭, 后来还是使用delphi下最快的脚本编译器PaxCompiler吧,虽然他要先编译在执行脚本,在安卓下,编译很慢,一个简单的脚本编译一下就有明显的卡顿,但是也无所谓了,他支持将脚本预编译成二进制文件,然后可以直接加载这个二进制文件执行,原生的delphi语法,还不用去再学习lua的语法,方便,我自己的做法是游戏开始加载的时候将所有脚本文件都编译成二进制文件或者直接发布二进制的脚本,这样游戏执行脚本是非常块的,比lua还要快,完全满足游戏脚本的使用,记录下,PaxCompiler类声明的方法,将一个类声明给脚本使用,其实现在的脚本支持RTII的方式,不用声明,不过还有点小问题具体也不算问题,是关于类继承后的一些处理, 所以,我还是喜欢自己声明下,下面是对QDAC的QJSON单元的不完全声明:


unit UJson;interfaceuses System.SysUtils, System.Classes, qjson, QString, PaxRegister;  procedure Register_Json;implementationfunction AddString(Self:TQJson; AName:string; AValue:string):Integer ;begin  Result:=Self.Add(AName,AValue) ;end;function AddInt64(Self:TQJson; AName:string; AValue:Int64):TQJson ;begin  Result:=Self.Add(AName,AValue) ;end;function AddName(Self:TQJson; AName:string):TQJson ;begin  Result:=Self.Add(AName) ;end;function AddBool(Self:TQJson; AName:string; AValue:Boolean):TQJson ;begin  Result:=Self.Add(AName,AValue) ;end;function AddExtended(Self:TQJson; AName:string; AValue:Extended):TQJson ;begin  Result:=Self.Add(AName,AValue) ;end;function AddAChild(Self:TQJson; AName:string; AChild:TQJson):Integer ;begin  Result:=Self.Add(AName,AChild) ;end;function AddArray(Self:TQJson; AName:string; AItems: array of const):TQJson ;begin  Result:=Self.Add(AName,AItems) ;end;function ItemByName(Self:TQJson; AName: QStringW): TQJson;begin  Result:=Self.ItemByName(AName) ;end;procedure Parse(Self:TQJson; const S: string);begin  Self.Parse(S);end;function GetAsJson(Self:TQJson):string ;begin  Result:=Self.AsJson ;end;procedure SetAsJson(Self:TQJson; const AValue:string) ;begin  Self.AsJson:=AValue ;end;function GetAsBytes(Self:TQJson):TBytes ;begin  Result:=Self.AsBytes ;end;procedure SetAsBytes(Self:TQJson; const AValue:TBytes) ;begin  Self.AsBytes:=AValue ;end;function GetAsVariant(Self:TQJson):Variant ;begin  Result:=Self.AsVariant ;end;procedure SetAsVariant(Self:TQJson; const AValue:Variant) ;begin Self.AsVariant:=AValue ;end;function GetCount(Self:TQJson):Integer ;begin  Result:=Self.Count ;end;procedure DeleteInt(Self:TQJson; AIndex:Integer) ;begin  Self.Delete(AIndex);end;procedure DeleteStr(Self:TQJson; AName:string) ;begin  Self.Delete(AName);end;procedure Delete(Self:TQJson) ;begin  Self.Delete;end;function GetAsBoolean(Self:TQJson):Boolean ;begin Result:=Self.AsBoolean ;end;procedure SetAsBoolean(Self:TQJson; const AValue:Boolean) ;begin  Self.AsBoolean:=AValue ;end;function GetAsInteger(Self:TQJson):Integer ;begin  Result:=Self.AsInteger ;end;procedure SetAsInteger(Self:TQJson; const AValue:Integer) ;begin  Self.AsInteger:=AValue ;end;function GetAsInt64(Self:TQJson):Int64 ;begin  Result:=Self.AsInt64 ;end;procedure SetAsInt64(Self:TQJson; const AValue:Int64) ;begin  Self.AsInt64:=AValue ;end;function GetAsFloat(Self:TQJson):Extended ;begin  Result:=Self.AsFloat ;end;procedure SetAsFloat(Self:TQJson; const AValue:Extended) ;begin  Self.AsFloat:=AValue ;end;function GetAsDateTime(Self:TQJson):TDateTime ;begin  Result:=Self.AsDateTime ;end;procedure SetAsDateTime(Self:TQJson; const AValue:TDateTime) ;begin  Self.AsDateTime:=AValue ;end;function TQJson_GetAsString(Self:TQJson):string ;begin  Result:=Self.AsString ;end;procedure TQJson_SetAsString(Self:TQJson; const AValue:string) ;begin  Self.AsString:=AValue ;end;function GetAsArray(Self:TQJson):string ;begin  Result:=Self.AsArray ;end;procedure SetAsArray(Self:TQJson; const AValue:string) ;begin  Self.AsArray:=AValue ;end;function GetItemIndex(Self:TQJson): Integer;begin Result:=Self.ItemIndex ;end;function GetItems(Self:TQJson;const AIndex: Integer): TQJson;begin Result:=Self.Items[AIndex] ;end;function TQJson_Add(Self:TQJson):TQJson ;begin  Result:=Self.Add ;end;{ TJson }procedure Register_Json;var G:Integer ;begin G:=RegisterClassType(0, TQJson); RegisterHeader(G,'constructor Create; overload;',@TQJson.Create) ; RegisterHeader(G,'destructor Destroy; override;',@TQJson.Destroy) ; RegisterHeader(G,'function ToString: string; overload;',@TQJson.ToString) ; RegisterHeader(G,'function Add: TQJson; overload;',@TQJson_Add) ; RegisterHeader(G,'function Add(AName, AValue: string): Integer; overload;',@AddString) ; RegisterHeader(G,'function Add(AName: string; AValue: Int64):TQJson; overload;',@AddInt64) ; RegisterHeader(G,'function Add(AName: string): TQJson; overload;',@AddName) ; RegisterHeader(G,'function Add(AName: string; AValue: Boolean): TQJson; overload;',@AddBool) ; RegisterHeader(G,'function Add(AName: string; AValue: Extended): TQJson; overload;',@AddExtended) ; RegisterHeader(G,'function Add(AName: string; AChild: TQJson): Integer; overload;',@AddAChild) ; RegisterHeader(G,'function Add(const AName: string; AItems: array of const): TQJson; overload;',@AddArray) ; RegisterHeader(G,'function AddDateTime(AName: string; AValue: TDateTime): TQJson; overload;',@TQJson.AddDateTime) ; RegisterHeader(G,'function AddVariant(AName: string; AValue: Variant): TQJson; overload;',@TQJson.AddVariant) ; RegisterHeader(G,'function ItemByName(AName: string): TQJson; overload;',@ItemByName) ; RegisterHeader(G,'function AddArray(AName: string): TQJson; overload;',@TQJson.AddArray) ; RegisterHeader(G,'procedure Parse(const S: string); overload;',@Parse) ; RegisterHeader(G,'procedure Delete(AIndex: Integer); overload; virtual;',@DeleteInt) ; RegisterHeader(G,'procedure Delete(AName: string); overload;',@DeleteStr) ; RegisterHeader(G,'procedure Delete; overload;',@Delete) ; RegisterHeader(G,'function ContainsValue(const AValue: Variant; ANest: Boolean = False;AStrict: Boolean = False): Boolean;',@TQJson.ContainsValue) ; RegisterHeader(G,'function IndexOf(const AName: string): Integer; virtual;',@TQJson.IndexOf) ; RegisterHeader(G,'procedure Clear; virtual;',@TQJson.Clear) ; RegisterHeader(G,'function _GetItems(AIndex: Integer): TQJson;',@GetItems) ; RegisterProperty(G,'property Items[AIndex: Integer]: TQJson read _GetItems; default;') ; RegisterHeader(G,'function GetItemIndex: Integer;',@GetItemIndex) ; RegisterProperty(G,'property ItemIndex: Integer read GetItemIndex;') ; RegisterHeader(G,'function GetAsArray:string ;',@GetAsArray) ; RegisterHeader(G,'procedure SetAsArray(const AValue:string) ;',@SetAsArray) ; RegisterProperty(G,'property AsArray: string read GetAsArray write SetAsArray;') ; RegisterHeader(G,'function _GetAsString:string ;',@TQJson_GetAsString) ; RegisterHeader(G,'procedure _SetAsString(const AValue:string) ;',@TQJson_SetAsString) ; RegisterProperty(G,'property AsString: string read _GetAsString write _SetAsString;') ; RegisterHeader(G,'function GetAsDateTime:TDateTime ;',@GetAsDateTime) ; RegisterHeader(G,'procedure SetAsDateTime(const AValue:TDateTime) ;',@SetAsDateTime) ; RegisterProperty(G,'property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;') ; RegisterHeader(G,'function GetAsFloat:Extended ;',@GetAsFloat) ; RegisterHeader(G,'procedure SetAsFloat(const AValue:Extended) ;',@SetAsFloat) ; RegisterProperty(G,'property AsFloat: Extended read GetAsFloat write SetAsFloat;') ; RegisterHeader(G,'function GetAsInt64:Int64 ;',@GetAsInt64) ; RegisterHeader(G,'procedure SetAsInt64(const AValue:Int64) ;',@SetAsInt64) ; RegisterProperty(G,'property AsInt64: Int64 read GetAsInt64 write SetAsInt64;') ; RegisterHeader(G,'function GetAsInteger:Integer ;',@GetAsInteger) ; RegisterHeader(G,'procedure SetAsInteger(AValue:Integer) ;',@SetAsInteger) ; RegisterProperty(G,'property AsInteger: Integer read GetAsInteger write SetAsInteger;') ; RegisterHeader(G,'function GetAsJson:string ;',@GetAsJson) ; RegisterHeader(G,'procedure SetAsJson(const AValue:string) ;',@SetAsJson) ; RegisterProperty(G,'property AsJson: string read GetAsJson write SetAsJson;') ; RegisterHeader(G,'function GetAsBytes:TBytes ;',@GetAsBytes) ; RegisterHeader(G,'procedure SetAsBytes(const AValue:TBytes) ;',@SetAsBytes) ; RegisterProperty(G,'property AsBytes: TBytes read GetAsBytes write SetAsBytes;') ; RegisterHeader(G,'function GetAsVariant:Variant ;',@GetAsVariant) ; RegisterHeader(G,'procedure SetAsVariant(const AValue:Variant) ;',@SetAsVariant) ; RegisterProperty(G,'property AsVariant: Variant read GetAsVariant write SetAsVariant;') ; RegisterHeader(G,'function GetCount:Integer ;',@GetCount) ; RegisterProperty(G,'property Count: Integer read GetCount;') ; RegisterHeader(G,'function GetAsBoolean:Boolean ;',@GetAsBoolean) ; RegisterHeader(G,'procedure SetAsBoolean(const AValue:Boolean) ;',@SetAsBoolean) ; RegisterProperty(G,'property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;') ;end;end.


原创粉丝点击