Creating besen objects from application side + passing to functions #19

Open
opened 2018-11-19 08:56:49 +00:00 by JernejL · 4 comments
JernejL commented 2018-11-19 08:56:49 +00:00 (Migrated from github.com)

type..

TActorInterface = class(TBESENNativeObject)

class is registered properly so it can be prototyped from:

BesenInst.RegisterNativeObject('Actor', TActorInterface);

So i try to create a object on my side, and pass it as parameter to javascript

    JsPlayer: TBESENValue;

	AResult: TBESENValue;
    ta: Tactor;
    JsCreatedPlayer: TActorInterface;

begin

 				TBESEN(BesenInst).GarbageCollector.Protect(OnCreatePlayer);

 			    try
 			       AResult.ValueType := bvtBOOLEAN;

                   ta:= Tactor.GetFromIndex(PlayerID);

                   JsCreatedPlayer:= TActorInterface.Create(BesenInst, TBESEN(BesenInst).ObjectPrototype, false);
                   JsCreatedPlayer.SetHandle(ta.GetHandle());

 				   TBESEN(BesenInst).GarbageCollector.Add(JsCreatedPlayer);
                   TBESEN(BesenInst).GarbageCollector.Protect(TBESENObject(JsCreatedPlayer));

                   a[0]:= @JsPlayer;
                   JsPlayer := BESENObjectValue(TBESENObject(JsCreatedPlayer));
                   // todo: add parameter player ID

 			       OnCreatePlayer.Call(BESENObjectValue(OnCreatePlayer), @a, 2, AResult);

 			    except
 			       on e: EBESENError do
 			       begin
 			         addtochat(Format('%s ( Line %d ): %s', [e.Name, TBESEN(BesenInst).LineNumber, e.Message]));
 			       end;

 			       on e: exception do
 			       begin
 			         addtochat(Format('%s ( Line %d ): %s', ['Exception', TBESEN(Instance).LineNumber, e.Message]));
 			       end;
 			    end;


If i print the object it's:
[object TActorInterface$Constructor] {}

Looks like some sort of empty object, it doesn't function properly in javascript (cannot change properties, etc.. ).

I've based my code on what i saw in https://github.com/Coldzer0/Cmulator/ project, i'm guessing i did something very wrong.

I'd just like to create an instance of native object, and pass it to function, so that properties and all can be correctly used as if it was created within javascript.

If you have a better method of contacting i'll take it, as i'm abusing tickets for help / support :( i'm in #besen channel but you are usually not reachable there.

type.. TActorInterface = class(TBESENNativeObject) class is registered properly so it can be prototyped from: BesenInst.RegisterNativeObject('Actor', TActorInterface); So i try to create a object on my side, and pass it as parameter to javascript ``` JsPlayer: TBESENValue; AResult: TBESENValue; ta: Tactor; JsCreatedPlayer: TActorInterface; begin TBESEN(BesenInst).GarbageCollector.Protect(OnCreatePlayer); try AResult.ValueType := bvtBOOLEAN; ta:= Tactor.GetFromIndex(PlayerID); JsCreatedPlayer:= TActorInterface.Create(BesenInst, TBESEN(BesenInst).ObjectPrototype, false); JsCreatedPlayer.SetHandle(ta.GetHandle()); TBESEN(BesenInst).GarbageCollector.Add(JsCreatedPlayer); TBESEN(BesenInst).GarbageCollector.Protect(TBESENObject(JsCreatedPlayer)); a[0]:= @JsPlayer; JsPlayer := BESENObjectValue(TBESENObject(JsCreatedPlayer)); // todo: add parameter player ID OnCreatePlayer.Call(BESENObjectValue(OnCreatePlayer), @a, 2, AResult); except on e: EBESENError do begin addtochat(Format('%s ( Line %d ): %s', [e.Name, TBESEN(BesenInst).LineNumber, e.Message])); end; on e: exception do begin addtochat(Format('%s ( Line %d ): %s', ['Exception', TBESEN(Instance).LineNumber, e.Message])); end; end; ``` If i print the object it's: [object TActorInterface$Constructor] {} Looks like some sort of empty object, it doesn't function properly in javascript (cannot change properties, etc.. ). I've based my code on what i saw in https://github.com/Coldzer0/Cmulator/ project, i'm guessing i did something very wrong. I'd just like to create an instance of native object, and pass it to function, so that properties and all can be correctly used as if it was created within javascript. If you have a better method of contacting i'll take it, as i'm abusing tickets for help / support :( i'm in #besen channel but you are usually not reachable there.
BeRo1985 commented 2018-11-19 12:40:32 +00:00 (Migrated from github.com)

Can you upload a complete test project with your issue?

Can you upload a complete test project with your issue?
JernejL commented 2018-11-19 13:11:37 +00:00 (Migrated from github.com)

I will try to make an isolated example.

As for object creation logic, does that seem correct way to do it at all?

I will try to make an isolated example. As for object creation logic, does that seem correct way to do it at all?
JernejL commented 2018-11-19 14:39:29 +00:00 (Migrated from github.com)

Ok, here is a whole self-contained lazarus project that does what i experimented with, binary and all code included:

https://gtamp.com/tdc/besenexperiment.7z

I'm sure i'm doing a lot of things wrong or things could be done better, so i will take any kind of feedback on how to integrate besen better / properly.

I'm still learning on how besen works, but maybe out of this i can build a few more detailed examples and some nice documentation.

Ok, here is a whole self-contained lazarus project that does what i experimented with, binary and all code included: https://gtamp.com/tdc/besenexperiment.7z I'm sure i'm doing a lot of things wrong or things could be done better, so i will take any kind of feedback on how to integrate besen better / properly. I'm still learning on how besen works, but maybe out of this i can build a few more detailed examples and some nice documentation.
JernejL commented 2018-12-01 13:10:41 +00:00 (Migrated from github.com)

Writing again, just as notification.. i made the example and linked it here.

Writing again, just as notification.. i made the example and linked it here.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
BeRo1985/besen#19
No description provided.