Closed Vizit0r closed 3 years ago
How are you importing the methods and TStringList type?
The following works in Simba
procedure CallGood( abc : TStringList );
begin
abc.Add('test123'); //all ok
end;
procedure CallBad(const abc : TStringList);
begin
abc.Add('test123'); //Error: Variable expected
end;
var foo:TStringList;
begin
foo.init();
CallGood(foo);
CallBad(foo);
end.
@ollydev
// LapeImport_TStringList(Compiler, 'TStringList');
procedure LapeImport_TStringList(Compiler : TLapeCompiler; ClassNamePrefix : String);
begin
//TStringList
Compiler.addGlobalType('record f_f : Integer; end', ClassNamePrefix);
Compiler.addGlobalMethod(Format('function %s.Create: TStringList;',[ClassNamePrefix]), @TStringList_Create, nil);
Compiler.addGlobalMethod(Format('procedure %s.Free;',[ClassNamePrefix]), @TStringList_Free, nil);
Compiler.addGlobalFunc(Format('function %s.Add(S: String): Integer;',[ClassNamePrefix]), @TStringList_Add);
....
end;
procedure TStringList_Create(const Params: PParamArray; const Result: Pointer);
begin
PObject(Result)^ := TStringList.Create;
PObject(Params^[0]) := PObject(Result);
end;
procedure TStringList_Free(const Params: PParamArray);
var _Self : TObject;
begin
_Self := PObject(Params^[0])^;
TStringList(_Self).Free;
PObject(Params^[0])^ := nil;
end;
procedure TStringList_Add(const Params: PParamArray; const Result: Pointer);
var _Self : TObject;
begin
_Self := PObject(Params^[0])^;
PInteger(Result)^ := TStringList(_Self).Add(PlpString(Params^[1])^);
end;
seems like my import is not correct, will try to use your importer. No documentation at all, even basic, searching a way blinded(
Append constref
like so: function %s.Add(S: String): Integer; constref;
This will tell Lape that Self
is not being modifed and your script should work.
Lape should ideally handle this better, without needing a hint. But it is what it is.
@Vizit0r ^
update according to Simba import, works now.
thank you.
Examples: 1)
2) Error with same root cause