B4J Question B4JS, ABMaterial, BANano, and alternatives

RobertK

Member
Licensed User
Longtime User
Hello @Erel and all the group. It's good to be back in the Forum after an extended absence.

I am currently looking for a simple lightweight solution to convert B4J Subs to JavaScript functions, without the need for integrated web development or UI design tools. Consider the following trivial example and please excuse any syntax errors.

B4X:
Sub Pythagoras(a As Double, b As Double) As Double
    Dim c As Double
    c = Sqrt((a*a) + (b*b))
    Return c   
End Sub

JavaScript:
Function Pythagoras(a, b) {
let c = Math.sqrt((a*a)+(b*b));
return c;
}

There is a quite a bit of information, both on and off the Forum, about B4JS, ABMaterial, and BANano, dating from approximately 2018 to 2021. Among the sources I have consulted are:


I see that @alwaysbusy and others have invested considerable effort in this project and, at first glance, it seems like a comprehensive solution capable of much more than I need at this stage. I am certain it includes the capability to do what I am looking for but, unfortunately, I have not yet been able to locate it. Perhaps someone familiar with the library could help guide me to the right place in the documentation or provide a quick walk-through.

Another approach might be to try to filter and modify the contents of the .java file generated by the B4J compiler. In the case of the above example, it looks like:

Java:
public static double  _pythagoras(double _a,double _b) throws Exception{
double _c = 0;
 //BA.debugLineNum = 23;BA.debugLine="Sub Pythagoras(a As Double, b As Double) As Double";
 //BA.debugLineNum = 25;BA.debugLine="Dim c As Double";
_c = 0;
 //BA.debugLineNum = 27;BA.debugLine="c = Sqrt((a*a) + (b*b))";
_c = anywheresoftware.b4a.keywords.Common.Sqrt((_a*_a)+(_b*_b));
 //BA.debugLineNum = 29;BA.debugLine="Return c";
if (true) return _c;
 //BA.debugLineNum = 31;BA.debugLine="End Sub";
return 0;
}

Is there any documentation for this file? And even if there is, this approach feels too much like reverse-engineering instead of a simple solution to a simple problem.

Have I overlooked something? Any advice would be greatly appreciated. Many Thanks!
 
Top