B4R Question Whether Pointers can be supported

santook

Member
Can B4R support operations like AddressOf, so that in inline C, you can use Pointers to pass functions or other types?
Object objects use wrapNumber, not wrapPointer, by default.

[CODE lang="b4x" highlight="25"]
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
End Sub

Private Sub AppStart
Dim o As Object
Serial1.Initialize(115200)
Log("AppStart")
'example of connecting to a local network
If wifi.Connect2("NantongCorona", "14725836") Then
Log("Connected to network")
Else
Log("Failed to connect to network")
End If
o=fun1
'Like this
'o=AddressOf(fun1)

RunNative("gofun1",o)

End Sub

Private Sub fun1()
Log("Hello World!")
End Sub


#if C

void gofun1(B4R::Object* o)
{
void (*p)();
p=(void(*)())o->data.PointerField;
p();
}
#End If[/CODE]
 
You should write a library and use the events mechanism, which is based on function pointers.

 
Upvote 0
Yes, I know how to write libraries and events. While this is great, there is a problem with it, which is that it is not conducive to personalization and maintenance. Modules and inline C can. It also saves resources and multiple calls.
Given that AddressOf is supported, I think this is a good choice.
 
Upvote 0
Back
Top