Just starting out? Need help? Post your questions and find answers here.
User avatar
Peter
 
Posts: 641
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

LibraryMaker.exe?

by Peter Sun Nov 10, 2019 8:18 pm

Hello,

does anyone know what the LibraryMaker.exe in the SDK folder is good for?

Image

@Fred?

Greetings ... Peter
hoerbie
 
Posts: 30
Joined: Sun Mar 17, 2019 5:51 pm

Re: LibraryMaker.exe?

by hoerbie Tue Nov 12, 2019 11:28 am

Hi,

I would say, it is the same as in PB, a tool for building own library files.

If you have a look at the files in the "libraries" directory you see, that this files have a "header" where the SB functions are defined, like they are shown as a hint in SB footer while typing in a function call, and in the same files "body" there are all the SB functions in JS defined.

If you do a search in the PB forums for "librarymaker" you will find some old postings about.

Greetings, Hoerbie
Fred
Site Admin
 
Posts: 1182
Joined: Mon Feb 24, 2014 10:51 am

Re: LibraryMaker.exe?

by Fred Tue Nov 12, 2019 12:19 pm

It seems like the libmaker shipped with the Windows version didn't worked correctly. It should be OK for the nex version. In the meantime, you can download this package which contains the new LibMaker and 2 examples to build lib:

https://www.spiderbasic.com/download/Examples.zip

Be sure to create your lib in the SpiderBasic/Libraries folder (and not in UserLibraries as it doesn't seem to work for now). You can use the GUI or the commandline

Here is the 'Easy' example for reference:

Easy.desc
Code: Select all
; For SpiderBasic, always C
C

; Number of cordova plugins to use
;
0

; For SpiderBasic, always LIB
;
LIB

; SpiderBasic libraries needed by the library
;
0

; Help directory name
;
Easy

; Library functions (FunctionName, Arg1, Arg2, ...)
;

; Fonction without any argument which returns a string
;
Easy42 () - Returns the number 42
Long

; Function without any argument which returns a double
;
EasyPI () - Returns the number PI
Double

; Function without any argument which returns a string
;
EasyString () - Returns the string "Hello World"
String

; Function with 1 argument which returns string
;
EasyConcatString, String, (Text$) - Returns the string "Hello " + Text$
String

; Function with 2 arguments which returns the sum of 2 integer parameters
;
EasyAdd, Long, Long, (Number1, Number2) - Returns the sum of the 2 numbers
Long

; Function without argument which increase a persistent value
;
EasyIncrease () - Returns the current increased value
Long

; Function with 3 optional parameters
;
EasyAddOptional, Long, [Long], [Long, Long], (Number1 [Number2, [Number3, Number4]) - Returns the sum of the specified numbers
Long

; Function without argument which increase a persistent value
;
EasyFillArray, Array, (Array()) - Fill the array with random numbers
None


Easy.js
Code: Select all
/*
 * 'Easy' library code
 *
 * Self explanatory example to build a new user library for SpiderBasic
 *
 * Library rules:
 * - All SpiderBasic function needs to be prefixed by 'spider_'
 * - If you need private variables for your library, you can use a scope: spider.yourlibraryname
 * - If a function returns a number, 'null' or 'undefined' return is not allowed. The function must always return a number even for it's default case
 * - If a function returns a string, 'null' or 'undefined' return is not allowed. The function must always return a string even for it's default case
 * - A function parameter is always strongly typed according to the type set in the .desc file. It can never be 'null', 'undefined' etc.
 * 
 * To compiler the lib (Windows):
 * "%SPIDERBASIC_HOME%/SDK/LibraryMaker/LibraryMaker.exe" /NOLOG /TO %SPIDERBASIC_HOME%/Libraries/
 */

/* Our private scope where we can define objects which will be shared between the function lib
 */
spider.easy = {
  currentEasyNumer: 0,
};


function spider_Easy42()
{
  return 42;
}


function spider_EasyPI()
{
  return Math.PI;
}


function spider_EasyString()
{
  return "Hello world";
}


function spider_EasyConcatString(text)
{
  if (text != "") // Only great if we pass a none empty string
  {
    return "Hello " + text + " !";
  }
 
  return "";
}


function spider_EasyAdd(number1, number2)
{
  return number1 + number2; // number1 and number2 are granted to be numbers, never 'undefined', 'null', 'bool' or 'string' etc.
}


function spider_EasyIncrease()
{
  spider.easy.currentEasyNumer++; // Use private object for persistant value
  return spider.easy.currentEasyNumer;
}


function spider_EasyAddOptional(number1, number2, number3, number4)
{
  if (typeof number2 === "undefined") number2 = 0; // optional parameter
  if (typeof number3 === "undefined") number3 = 0; // optional parameter
  if (typeof number4 === "undefined") number4 = 0; // optional parameter

  return number1 + number2 + number3 + number4;
}


//
// Array object:
//  array.array: javascript array containing the data
//  array.type: type of the array (#PB_Long, #PB_String, #PB_Double)
//  array.nbDimensions = nb of dimension in the array
//  array.dimensions: array of array for each dimension
//  array.structure: associated structure (if any)
//
function spider_EasyFillArray(array)
{
  if (array.nbDimensions == 1) // Only support array with one dimension
  {
    var array;
   
    for (var i = 0 ; i < array.array.length; i++)
    {
      array.array[i] = (Math.random() * 100) | 0; // generate an integer number between 0 and 100
    }
  }
}


Easy.sb
Code: Select all
Debug Easy42()
Debug EasyPI()
Debug EasyString()
Debug EasyConcatString("Timo")
Debug EasyAdd(2, 20)

Debug "Increase internal value 3 times:"
Debug EasyIncrease()
Debug EasyIncrease()
Debug EasyIncrease()

Debug "Display randomized array:"

Dim Numbers(3)
EasyFillArray(Numbers())

For i = 0 To 3
  Debug Numbers(i)
Next

Debug "EasyAddOptional: " + EasyAddOptional(1)
Debug "EasyAddOptional: " + EasyAddOptional(1, 2)
Debug "EasyAddOptional: " + EasyAddOptional(1, 2, 3, 4)

User avatar
Danilo
 
Posts: 31
Joined: Wed Feb 26, 2014 7:11 am

Re: LibraryMaker.exe?

by Danilo Tue Nov 12, 2019 1:45 pm

Thank you very much! Image
cya,
...Danilo
User avatar
Peter
 
Posts: 641
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: LibraryMaker.exe?

by Peter Tue Nov 12, 2019 1:48 pm

Great!

It finally allows us to seamlessly integrate new libraries. :D

Thanks a lot, Fred! .... Peter
Fred
Site Admin
 
Posts: 1182
Joined: Mon Feb 24, 2014 10:51 am

Re: LibraryMaker.exe?

by Fred Tue Nov 12, 2019 1:53 pm

Please note than your still need to build your lib for the 3 OS (one Windows compiled lib can't be used on OS X and vice-versa)
User avatar
Danilo
 
Posts: 31
Joined: Wed Feb 26, 2014 7:11 am

Re: LibraryMaker.exe?

by Danilo Sat Nov 16, 2019 9:55 am

Fred wrote:Please note than your still need to build your lib for the 3 OS (one Windows compiled lib can't be used on OS X and vice-versa)

Could you make the lib format platform-independent?

If it's only JavaScript, it would be nice to use the libs on all platforms (create on macOS, use on Windows).
cya,
...Danilo
Fred
Site Admin
 
Posts: 1182
Joined: Mon Feb 24, 2014 10:51 am

Re: LibraryMaker.exe?

by Fred Sat Nov 16, 2019 5:20 pm

For now all the code is shared with PureBasic, that's why it's plateform dependant. I will try to change that
the.weavster
 
Posts: 171
Joined: Sat Mar 01, 2014 3:02 pm

Re: LibraryMaker.exe?

by the.weavster Sun Nov 17, 2019 9:41 am

This is cool :D

Fred wrote:For now all the code is shared with PureBasic, that's why it's plateform dependant. I will try to change that

Any chance it will be cross platform when the latest release comes out of beta?
User avatar
Peter
 
Posts: 641
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

Re: LibraryMaker.exe?

by Peter Sun Nov 17, 2019 12:38 pm

Fred wrote:I will try to change that

that's good news. Image Then I will wait a while before releasing my libraries.

Thanks and Greetings ... Peter
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 2 guests