Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Support

Pages: 1 ... 3 4 [5] 6 7 ... 59
61
General Discussions / Re: ISAM - An appeal
« on: December 18, 2016, 12:01:27 PM »
I just downloaded and built from source the current BerkleyDB  (without encryption)  I'm going to try and compile the BDB extension module on Linux 64 bit and see if it will work with the current library.

I gave it a shot but the dbenv structure/functionality has changed and the Script BASIC interface.c for the extension module needs upgrading.

Quote from: Oracle
DBENV structure changes:

    The db_errcall, db_errfile, db_errpfx and db_paniccall fields of the DBENV structure have been deprecated and their functionality replaced by the DBENV->set_errcall, DBENV->set_errfile, DBENV->set_errpfx and DBENV->set_paniccall methods.
    The db_verbose field of the DBENV structure has been replaced by the DBENV->set_verbose method.
    The lk_conflicts, lk_detect, lk_max and lk_modes fields of the DBENV structure have been replaced by the DBENV->set_lk_conflicts, DBENV->set_lk_detect and DBENV->set_lk_max methods.
    The lg_max field of the DBENV structure has been replaced by the DBENV->set_lg_max method.
    The mp_mmapsize and mp_size fields of the DBENV structure have been replaced by the DBENV->set_cachesize and DBENV->set_mp_mmapsize methods.
    The tx_info, tx_max and tx_recover fields of the DBENV structure have been replaced by the DBENV->set_tx_max and DBENV->set_tx_recover methods.
    The (unused) DBENV->db_lorder field has been deleted.


jrs@jrs-laptop:~/BerkleyDB/db-6.2.23.NC/build_unix$ sudo make install
[sudo] password for jrs:
Installing DB include files: /usr/include ...
Installing DB library: /usr/lib ...
libtool: install: cp -p .libs/libdb-6.2.so /usr/lib/libdb-6.2.so
libtool: install: cp -p .libs/libdb-6.2.lai /usr/lib/libdb-6.2.la
libtool: install: cp -p .libs/libdb-6.2.a /usr/lib/libdb-6.2.a
libtool: install: chmod 644 /usr/lib/libdb-6.2.a
libtool: install: ranlib /usr/lib/libdb-6.2.a
libtool: install: cp -p libdb.a /usr/lib/libdb.a
libtool: install: chmod 644 /usr/lib/libdb.a
libtool: install: ranlib /usr/lib/libdb.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /usr/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing DB utilities: /usr/bin ...
libtool: install: cp -p .libs/db_archive /usr/bin/db_archive
libtool: install: cp -p .libs/db_checkpoint /usr/bin/db_checkpoint
libtool: install: cp -p .libs/db_deadlock /usr/bin/db_deadlock
libtool: install: cp -p .libs/db_dump /usr/bin/db_dump
libtool: install: cp -p .libs/db_hotbackup /usr/bin/db_hotbackup
libtool: install: cp -p .libs/db_load /usr/bin/db_load
libtool: install: cp -p .libs/db_log_verify /usr/bin/db_log_verify
libtool: install: cp -p .libs/db_printlog /usr/bin/db_printlog
libtool: install: cp -p .libs/db_recover /usr/bin/db_recover
libtool: install: cp -p .libs/db_replicate /usr/bin/db_replicate
libtool: install: cp -p .libs/db_stat /usr/bin/db_stat
libtool: install: cp -p .libs/db_tuner /usr/bin/db_tuner
libtool: install: cp -p .libs/db_upgrade /usr/bin/db_upgrade
libtool: install: cp -p .libs/db_verify /usr/bin/db_verify
Installing documentation: /usr/docs ...
jrs@jrs-laptop:~/BerkleyDB/db-6.2.23.NC/build_unix$


This is where it died trying to compile the BDB extension module.


jrs@jrs-laptop:~/sb/source/extensions/bdb$ make -B
gcc -O2 -w -m64 -fPIC -DSTATIC_LINK=1 -c -o /home/jrs/sb/source/bin/mod/obj/bdb/s_interface.o interface.c
interface.c: In function ‘bootmodu’:
interface.c:153:44: error: ‘DB_ENV {aka struct __db_env}’ has no member named ‘mp_size’
 #define X(A,B) if( s=besCONFIG(A) )p->dbenv->B = atol(s);
                                            ^
interface.c:160:3: note: in expansion of macro ‘X’
   X("bdb.limits.mp_size"    ,mp_size)
   ^
makefile:19: recipe for target '/home/jrs/sb/source/bin/mod/obj/bdb/s_interface.o' failed
make: *** [/home/jrs/sb/source/bin/mod/obj/bdb/s_interface.o] Error 1
jrs@jrs-laptop:~/sb/source/extensions/bdb$


62
General Discussions / Re: ISAM - An appeal
« on: December 18, 2016, 09:47:22 AM »
Here is the Script BASIC include file for the BerkleyDB extension module that hasn't been updated in years. If you would like a zip of the extension module source for it, let me know.

Quote from: BDB Documentation
This document describes how to install and use the module BDB developed to help programmers writing database-handling programs in ScriptBasic. The module BDB is based on the Berkeley Data Base from Sleepy Cat Software Inc.

There are separate documents that describe the language (Users’ Guide), the major architecture of the source code (Source Guide).

This document describes the version 2.0 of the module.

The Berkeley Database (bdb) is a set of database handling routines. The program using the bdb directly calls these routines. There is no SQL server or a database daemon. In this sense this is a library collection that can handle simple database structures.

Although it is cumbersome to write complex database application using the Berkeley database lacking SQL interface it pays back on performance.

The Berkeley Database is available on Windows NT as well as on UNIX. It supports transaction handling and is it capable handling really huge databases. Therefore it is an ideal choice for several types of application where there is no need to separate the application from the database.

The bdb module developed for ScriptBasic provides an interface to a subset of the Berkeley Database functions. Using the module the BASIC program can use database handling functions, and transactions. On the other hand BASIC programs can not directly use the shared memory management functions, or locking (only through transactions). Application programmers needing these functions should rather consider developing their own ScriptBasic module using the language C delivering their application specific functions using the underlying Berkeley Database functions.

The functions available to BASIC programmers allow database creation, inserting, deleting, updating, searching data element with single or duplicated keys, start, commit and abort transactions. Some functions are simplified. The BASIC interface does not resemble to the C API of the Berkeley Database. Rather it is a BASIC language database-handling interface that happens to use the Berkeley Database.


Code: Script BASIC
  1. '
  2. ' FILE: bdb.bas
  3. '
  4. ' This is the module declaration of the ScriptBasic external module bdb
  5. '
  6. ' To use this module you have to have bdb.dll or bdb.so installed in the
  7. ' modules directory.
  8. '
  9. ' These implement the interface to the Berkeley Data Base library
  10.  
  11. module bdb
  12.  
  13. ' Error codes
  14. Const ErrorInvalidFileName      = &H80001
  15. Const ErrorInvalidDbHandle      = &H80002
  16. Const ErrorTransactionnotClosed = &H80003
  17. Const ErrorTransactionNotOpened = &H80004
  18. Const ErrorKeyNotFound          = &H80005
  19. Const ErrorIncomplete           = &H80006
  20. Const ErrorKeyEmpty             = &H80007
  21. Const ErrorKeyExist             = &H80008
  22. Const ErrorLockDeadLock         = &H80009
  23. Const ErrorLockNotGranted       = &H8000A
  24. Const ErrorNotFound             = &H8000B
  25. Const ErrorOldVersion           = &H8000C
  26. Const ErrorRunRecovery          = &H8000D
  27. Const ErrorDeleted              = &H8000E
  28. Const ErrorNeedSplit            = &H8000F
  29. Const ErrorSwapBytes            = &H80010
  30. Const ErrorTxnCkp               = &H80011
  31.  
  32.  
  33. ' Table types
  34. Const BTree   = &H01
  35. Const Hash    = &H02
  36. Const Recno   = &H04
  37. Const Queue   = &H08
  38. Const Unknown = &H10
  39.  
  40. ' put flags
  41. Const Append      = &HFFFFFFFE
  42. Const NoOverWrite = &HFFFFFFFD
  43.  
  44. ' Table opening flags
  45. Const Create   = &HFFFFFFFE
  46. Const NoMap    = &HFFFFFFFD
  47. Const RdOnly   = &HFFFFFFFB
  48. Const Thread   = &HFFFFFFF7
  49. Const Trunc    = &HFFFFFFEF
  50. Const New      = &HFFFFFFDF
  51.  
  52. ' open the database
  53. ' DB = bdb::Open(DataBase,type,flags,unixmode)
  54. declare sub ::Open alias "sb_db_open" lib "bdb"
  55.  
  56. ' close the DB
  57. ' bdb::Close DB
  58. declare sub ::Close alias "sb_db_close" lib "bdb"
  59.  
  60. ' put a new, possibly duplicated key/value pairinto DB
  61. ' bdb::Put DB,key,value
  62. declare sub ::Put alias "sb_db_put" lib "bdb"
  63.  
  64. ' update the last accessed record
  65. ' bdb::Update DB,value
  66. declare sub ::Update alias "sb_db_update" lib "bdb"
  67. ' delete the last accessed record
  68. ' bdb::DeleteRecord DB
  69. declare sub ::DeleteRecord alias "sb_db_eracrec" lib "bdb"
  70.  
  71. ' get value matching the key from DB
  72. ' if there are more than one values for the same key return the first one
  73. ' value = bdb::Get(DB,key)
  74. declare sub ::Get alias "sb_db_get" lib "bdb"
  75. ' value = bdb::First(DB,key) or value = bdb::First(DB)
  76. declare sub ::First alias "sb_db_get" lib "bdb"
  77.  
  78. ' get the last value from DB
  79. ' value = bdb::Last(DB)
  80. declare sub ::Last alias "sb_db_last" lib "bdb"
  81.  
  82. ' get the next value for the key or undef if there are no more
  83. ' value = bdb::Next(DB,key)
  84. declare sub ::Next alias "sb_db_next" lib "bdb"
  85. ' get the previous value for the key or undef if there are no more
  86. ' value = bdb::Previous(DB,key)
  87. declare sub ::Previous alias "sb_db_prev" lib "bdb"
  88.  
  89. ' delete all records for the given key
  90. ' bdb::DeleteAll DB,key
  91. declare sub ::DeleteAll alias "sb_db_del" lib "bdb"
  92.  
  93. ' get the key of the last accessed record
  94. ' bdb::Key(DB)
  95. declare sub ::Key alias "sb_db_key" lib "bdb"
  96.  
  97. ' transaction handling, no arguments
  98. declare sub ::BeginTransaction alias "sb_db_transact" lib "bdb"
  99. declare sub ::CommitTransaction alias "sb_db_trcommit" lib "bdb"
  100. declare sub ::EndTransaction alias "sb_db_trcommit" lib "bdb"
  101. declare sub ::AbortTransaction alias "sb_db_trabort" lib "bdb"
  102.  
  103. ' delete a database table
  104. ' bdb::Drop "databasename"
  105. declare sub ::Drop alias "sb_db_remove" lib "bdb"
  106.  
  107. end module
  108.  

63
Documentation / Re: Script BASIC Commands & Functions Reference
« on: December 14, 2016, 02:38:45 PM »
Thank You!


64
Documentation / Re: Script BASIC Commands & Functions Reference
« on: December 13, 2016, 06:06:03 PM »
Great job!

Thank you very much for your contribution to the Script BASIC project.

Quote
The editable document source is in Word, if anyone needs that 

I would like to keep a copy available to expand upon. I have Windows 2.2 Inno based Windows setup file with all the extension modules coming soon.

65
General Discussions / Re: module NT
« on: December 01, 2016, 02:23:18 PM »
I think your problem is that you didn't use the right key name. (LoggedOnUsername)
It works fine for me on Win7 32 bit version in a VirtualBox.

Quote from: john
I don't have Windows 10 to test this. Are you sure the registry key you are after is is really there? Can you access any other registry keys?

Code: Script BASIC
  1. Import nt.bas
  2.  
  3. print nt::RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\SessionData\\1\\LoggedOnUsername"),"\n"
  4.  


C:\sbgcc\examples\test>scriba testreg.sb
.\John

C:\sbgcc\examples\test>


Update - I now have Windows 10 installed and once I get Script BASIC setup on it I will try the NT registry access test but I don't expect any issues at this point.

Code: Script BASIC
  1. Import nt.bas
  2.  
  3. print nt::RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\SessionData\\1\\LoggedOnUser"),"\n"
  4.  


Microsoft Windows [Version 10.0.14393]

C:\sbgcc\examples\test>scriba testreg.sb
DESKTOP-FEE3LLO\John

C:\sbgcc\examples\test>




66
General Discussions / Re: module NT
« on: November 25, 2016, 10:42:25 AM »
Script_test,

The registry support functionality is provided by the NT (Windows only) extension module. Windows isn't my main focus extending Script BASIC in the future. If you have the skills to take ownership in resolving the NT issues, the project and I would greatly appreciate it. I hope to have Windows 10 installed in a VM soon for testing.

67
Extension Modules / JavaScript Extension Module
« on: November 18, 2016, 10:34:36 AM »
The Script BASIC JS extension module is based on Cesanta's V7 JavaScript Engine. It claims to be the world's smallest footprint JavaScript 5.1 compatible embeddable engine. There are no other dependencies required. I have attached a Ubuntu 16.04 64 bit binary shared object (.so) and interface include file. The js.inc is briefly documented but hopefully the following examples will get you started. This is just a first round beta and I would appreciate any feedback or examples you may be willing to share.

js.inc
Code: Script BASIC
  1. MODULE JS
  2.  
  3. ' CORE
  4. DECLARE SUB      js_create                  ALIAS "js_create"                 LIB "js"
  5. DECLARE SUB      js_destroy                 ALIAS "js_destroy"                LIB "js"
  6. DECLARE SUB      js_get_global              ALIAS "js_get_global"             LIB "js"
  7. DECLARE SUB      js_get_this                ALIAS "js_get_this"               LIB "js"
  8. DECLARE SUB      js_get_arguments           ALIAS "js_get_arguments"          LIB "js"
  9. DECLARE SUB      js_arg                     ALIAS "js_arg"                    LIB "js"
  10. DECLARE SUB      js_argc                    ALIAS "js_argc"                   LIB "js"
  11. DECLARE SUB      js_own                     ALIAS "js_own"                    LIB "js"
  12. DECLARE SUB      js_disown                  ALIAS "js_disown"                 LIB "js"
  13. DECLARE SUB      js_set_gc_enabled          ALIAS "js_set_gc_enabled"         LIB "js"
  14. DECLARE SUB      js_interrupt               ALIAS "js_interrupt"              LIB "js"
  15. DECLARE SUB      js_get_parser_error        ALIAS "js_get_parser_error"       LIB "js"
  16.  
  17. ' PRIMITIVES
  18. DECLARE SUB      js_mk_number               ALIAS "js_mk_number"              LIB "js"
  19. DECLARE SUB      js_get_double              ALIAS "js_get_double"             LIB "js"
  20. DECLARE SUB      js_get_int                 ALIAS "js_get_int"                LIB "js"
  21. DECLARE SUB      js_is_number               ALIAS "js_is_number"              LIB "js"
  22. DECLARE SUB      js_mk_boolean              ALIAS "js_mk_boolean"             LIB "js"
  23. DECLARE SUB      js_get_bool                ALIAS "js_get_bool"               LIB "js"
  24. DECLARE SUB      js_is_boolean              ALIAS "js_is_boolean"             LIB "js"
  25. DECLARE SUB      js_mk_null                 ALIAS "js_mk_null"                LIB "js"
  26. DECLARE SUB      js_is_null                 ALIAS "js_is_null"                LIB "js"
  27. DECLARE SUB      js_mk_undefined            ALIAS "js_mk_undefined"           LIB "js"
  28. DECLARE SUB      js_is_undefined            ALIAS "js_is_undefined"           LIB "js"
  29. DECLARE SUB      js_mk_foreign              ALIAS "js_mk_foreign"             LIB "js"
  30. DECLARE SUB      js_get_ptr                 ALIAS "js_get_ptr"                LIB "js"
  31. DECLARE SUB      js_is_foreign              ALIAS "js_is_foreign"             LIB "js"
  32.  
  33. ' STRINGS
  34. DECLARE SUB      js_mk_string               ALIAS "js_mk_string"              LIB "js"
  35. DECLARE SUB      js_is_string               ALIAS "js_is_string"              LIB "js"
  36. DECLARE SUB      js_get_string              ALIAS "js_get_string"             LIB "js"
  37. DECLARE SUB      js_get_cstring             ALIAS "js_get_cstring"            LIB "js"
  38.  
  39. ' OBJECTS
  40. DECLARE SUB      js_mk_object               ALIAS "js_mk_object"              LIB "js"
  41. DECLARE SUB      js_is_object               ALIAS "js_is_object"              LIB "js"
  42. DECLARE SUB      js_get_proto               ALIAS "js_get_proto"              LIB "js"
  43. DECLARE SUB      js_set_proto               ALIAS "js_set_proto"              LIB "js"
  44. DECLARE SUB      js_get                     ALIAS "js_get"                    LIB "js"
  45. DECLARE SUB      js_def                     ALIAS "js_def"                    LIB "js"
  46. DECLARE SUB      js_set                     ALIAS "js_set"                    LIB "js"
  47. DECLARE SUB      js_del                     ALIAS "js_del"                    LIB "js"
  48. DECLARE SUB      js_init_prop_iter_ctx      ALIAS "js_init_prop_iter_ctx"     LIB "js"
  49. DECLARE SUB      js_next_prop               ALIAS "js_next_prop"              LIB "js"
  50. DECLARE SUB      js_destruct_prop_iter_ctx  ALIAS "js_destruct_prop_iter_ctx" LIB "js"
  51. DECLARE SUB      js_is_instanceof           ALIAS "js_is_instanceof"          LIB "js"
  52. DECLARE SUB      js_is_instanceof_v         ALIAS "js_is_instanceof_v"        LIB "js"
  53.  
  54. ' ARRAYS
  55. DECLARE SUB      js_mk_array                ALIAS "js_mk_array"               LIB "js"
  56. DECLARE SUB      js_is_array                ALIAS "js_is_array"               LIB "js"
  57. DECLARE SUB      js_array_length            ALIAS "js_array_length"           LIB "js"
  58. DECLARE SUB      js_array_push              ALIAS "js_array_push"             LIB "js"
  59. DECLARE SUB      js_array_get               ALIAS "js_array_get"              LIB "js"
  60. DECLARE SUB      js_array_set               ALIAS "js_array_set"              LIB "js"
  61. DECLARE SUB      js_array_del               ALIAS "js_array_del"              LIB "js"
  62.  
  63. ' EXECUTION
  64. DECLARE SUB      js_exec                    ALIAS "js_exec"                   LIB "js"
  65. DECLARE SUB      js_exec_file               ALIAS "js_exec_file"              LIB "js"
  66. DECLARE SUB      js_apply                   ALIAS "js_apply"                  LIB "js"
  67. DECLARE SUB      js_parse_json              ALIAS "js_parse_json"             LIB "js"
  68. DECLARE SUB      js_parse_json_file         ALIAS "js_parse_json_file"        LIB "js"
  69.  
  70. 'REGEX
  71. DECLARE SUB      js_mk_regexp               ALIAS "js_mk_regexp"              LIB "js"
  72. DECLARE SUB      js_is_regexp               ALIAS "js_is_regexp"              LIB "js"
  73.  
  74. ' UTILITY
  75. DECLARE SUB      js_stringify               ALIAS "js_stringify"              LIB "js"
  76. DECLARE SUB      js_println                 ALIAS "js_println"                LIB "js"
  77.  
  78. DECLARE SUB      SB_shifts                  ALIAS "SB_shifts"                 LIB "js"
  79. DECLARE COMMAND  js_iif                     ALIAS "js_iif"                    LIB "js"
  80.  
  81.  
  82. ' JS Global Module Variables
  83. OBJ = 0
  84. SYS = 0
  85.  
  86. ' Stringify Modes
  87. DEFAULT = 0
  88. JSON    = 1
  89. DEBUG   = 2
  90.  
  91. ' Property Attribute Support
  92.  
  93. CONST V7_PROPERTY_NON_WRITABLE              = 1
  94. CONST V7_PROPERTY_NON_ENUMERABLE            = 2
  95. CONST V7_PROPERTY_NON_CONFIGURABLE          = 4
  96. CONST V7_PROPERTY_GETTER                    = 8
  97. CONST V7_PROPERTY_SETTER                    = 16
  98. CONST _V7_PROPERTY_HIDDEN                   = 32
  99. CONST _V7_PROPERTY_OFF_HEAP                 = 64
  100. CONST _V7_PROPERTY_USER_DATA_AND_DESTRUCTOR = 128
  101. CONST _V7_DESC_PRESERVE_VALUE               = 256
  102. CONST _V7_DESC_MASK                         = &HFFFF
  103.  
  104. CONST PROPERTY_DEFAULT = 0
  105.  
  106. ' TRUE or FALSE. Whether the property's value can be set.
  107. FUNCTION WRITABLE(v)
  108.   IF v THEN
  109.     WRITABLE = PROPERTY_DEFAULT
  110.   ELSE
  111.     WRITABLE = V7_PROPERTY_NON_WRITABLE
  112.   END IF
  113. END FUNCTION
  114.  
  115. ' TRUE or FALSE. Whether the property shows in some loop constructs.
  116. FUNCTION ENUMERABLE(v)
  117.   IF v THEN
  118.     ENUMERABLE = PROPERTY_DEFAULT
  119.   ELSE
  120.     ENUMERABLE = V7_PROPERTY_NON_ENUMERABLE
  121.   END IF
  122. END FUNCTION
  123.  
  124. ' TRUE or FALSE. Whether the property can be deleted and whether its attributes can be changed.
  125. FUNCTION CONFIGURABLE(v)
  126.   IF v THEN
  127.     CONFIGURABLE = PROPERTY_DEFAULT
  128.   ELSE
  129.     CONFIGURABLE = V7_PROPERTY_NON_CONFIGURABLE
  130.   END IF
  131. END FUNCTION
  132.  
  133. ' TRUE or FALSE. When a property is accessed the value is generated by calling a function implicitly.
  134. FUNCTION GETTER(v)
  135.   IF v THEN
  136.     GETTER = V7_PROPERTY_GETTER
  137.   ELSE
  138.     GETTER = FALSE
  139.   END IF
  140. END FUNCTION
  141.  
  142. ' TRUE or FALSE. When a property is set it will implicitly call a function and pass a
  143. ' value as argument, and the return value of the function is set to the property.
  144. FUNCTION SETTER(v)
  145.   IF v THEN
  146.     SETTER = V7_PROPERTY_SETTER
  147.   ELSE
  148.     SETTER = FALSE
  149.   END IF
  150. END FUNCTION
  151.  
  152. FUNCTION PRESERVE_VALUE
  153.     PRESERVE_VALUE = _V7_DESC_PRESERVE_VALUE
  154. END FUNCTION
  155.  
  156. FUNCTION HIDDEN(v)
  157.   IF v THEN
  158.     HIDDEN = V7_PROPERTY_HIDDEN
  159.   ELSE
  160.     HIDDEN = FALSE
  161.   END IF
  162. END FUNCTION
  163.  
  164. FUNCTION OFF_HEAP(v)
  165.   IF v THEN
  166.     OFF_HEAP = _V7_PROPERTY_OFF_HEAP
  167.   ELSE
  168.     OFF_HEAP = FALSE
  169.   END IF
  170. END FUNCTION
  171.  
  172.  
  173. ' JS API Function Wrappers
  174.  
  175. ' Create V7 instance
  176. FUNCTION CREATE
  177.   OBJ = js_create()
  178.   SYS = js_get_global(OBJ)
  179.   CREATE = OBJ
  180. END FUNCTION
  181.  
  182. ' Destroy V7 instance
  183. SUB DESTROY
  184.   js_destroy(OBJ)
  185.   UNDEF OBJ
  186. END SUB
  187.  
  188. ' Return root level (`global`) object of the given V7 instance
  189. FUNCTION GET_GLOBAL
  190.   GET_GLOBAL = js_get_global(OBJ)
  191. END FUNCTION
  192.  
  193. ' Return current `this` object
  194. FUNCTION GET_THIS
  195.   GET_THIS = js_get_this(OBJ)
  196. END FUNCTION
  197.  
  198. ' Return current `arguments` array
  199. FUNCTION GET_ARGUMENTS
  200.   GET_ARGUMENTS = js_get_arguments(OBJ)
  201. END FUNCTION
  202.  
  203. ' Return i-th argument
  204. FUNCTION ARG(i)
  205.   ARG = js_arg(OBJ, i)
  206. END FUNCTION
  207.  
  208. ' Return the length (`count`) of `arguments`
  209. FUNCTION ARGC
  210.   ARGC = js_argc(OBJ)
  211. END FUNCTION
  212.  
  213. ' Tells the GC about a JS value variable/field owned by `C` code.
  214. SUB OWN(v)
  215.   js_own(OBJ, v)
  216. END SUB
  217.  
  218. ' User code should also explicitly disown the variables with v7_disown
  219. ' once it goes out of scope or the structure containing the v7_val_t field is freed.
  220. ' Returns 1 if value is found, 0 otherwise
  221. FUNCTION DISOWN(v)
  222.   DISOWN = js_disown(OBJ, v)
  223. END FUNCTION
  224.  
  225. ' Enable or disable GC
  226. SUB SET_GC_ENABLED(enabled)
  227.   js_set_gc_enabled(OBJ, enabled)
  228. END SUB
  229.  
  230. ' It sets a flag that will cause the interpreter to throw an Interrupted Error
  231. SUB INTERRUPT
  232.   js_interrupt(OBJ)
  233. END SUB
  234.  
  235. ' Returns last parser error message
  236. FUNCTION GET_ERROR
  237.   GET_ERROR = js_get_parser_error(OBJ)
  238. END FUNCTION
  239.  
  240. ' Make numeric primitive value
  241. FUNCTION MK_NUMBER(num)
  242.   MK_NUMBER = js_mk_number(OBJ, num)
  243. END FUNCTION
  244.  
  245. ' Returns number value stored in `v7_val_t` as `double`
  246. FUNCTION GET_DOUBLE(v)
  247.   GET_DOUBLE = js_get_double(OBJ, v)
  248. END FUNCTION
  249.  
  250. ' Returns number value stored in `v7_val_t` as `int`. If the number
  251. ' value is not an integer, the fraction part will be discarded.
  252. FUNCTION GET_INT(v)
  253.   GET_INT = js_get_int(OBJ, v)
  254. END FUNCTION
  255.  
  256. ' Returns true if given value is a primitive number value
  257. FUNCTION IS_NUMBER(v)
  258.   IS_NUMBER = js_is_number(v)
  259. END FUNCTION
  260.  
  261. ' Make boolean primitive value (either `true` or `false`)
  262. FUNCTION MK_BOOLEAN(is_true)
  263.   MK_BOOLEAN = js_mk_boolean(OBJ, is_true)
  264. END FUNCTION
  265.  
  266. ' Returns boolean stored in `v7_val_t`: 0 for `false` or
  267. ' non-boolean, non-0 for `true`
  268. FUNCTION GET_BOOL(v)
  269.   GET_BOOL = js_get_bool(OBJ, v)
  270. END FUNCTION
  271.  
  272. ' Returns `true` if given value is a primitive boolean value
  273. FUNCTION IS_BOOLEAN(v)
  274.   IS_BOOLEAN = js_is_boolean(v)
  275. END FUNCTION
  276.  
  277. ' Make `null` primitive value
  278. FUNCTION MK_NULL
  279.   MK_NULL = js_mk_null()
  280. END FUNCTION
  281.  
  282. ' Returns true if given value is a primitive `null` value
  283. FUNCTION IS_NULL(v)
  284.   IS_NULL = js_is_null(v)
  285. END FUNCTION
  286.  
  287. ' Make `undefined` primitive value
  288. FUNCTION MK_UNDEFINED
  289.   MK_UNDEFINED = js_mk_undefined()
  290. END FUNCTION
  291.  
  292. ' Returns true if given value is a primitive `undefined` value
  293. FUNCTION IS_UNDEFINED(v)
  294.   IS_UNDEFINED = js_is_undefined(v)
  295. END FUNCTION
  296.  
  297. ' Make JavaScript value that holds C/C++ `void *` pointer
  298. FUNCTION MK_FOREIGN
  299.   MK_FOREIGN = js_mk_foreign(OBJ)
  300. END FUNCTION
  301.  
  302. ' Returns `void *` pointer stored in `v7_val_t`
  303. ' Returns NULL `undef` if the value is not a foreign pointer
  304. FUNCTION GET_PTR(v)
  305.   GET_PTR = js_get_ptr(OBJ, v)
  306. END FUNCTION
  307.  
  308. ' Returns true if given value holds `void *` pointer
  309. FUNCTION IS_FOREIGN(v)
  310.   IS_FOREIGN = js_is_foreign(v)
  311. END FUNCTION
  312.  
  313. ' Creates a string primitive value
  314. FUNCTION MK_STRING(strval)
  315.   MK_STRING = js_mk_string(OBJ, strval, LEN(strval), 1)
  316. END FUNCTION
  317.  
  318. ' Returns true if given value is a primitive string value
  319. FUNCTION IS_STRING(v)
  320.   IS_STRING = js_is_string(v)
  321. END FUNCTION
  322.  
  323. ' Returns a pointer to the string stored in `v7_val_t`
  324. FUNCTION GET_STRING(v)
  325.   GET_STRING = js_get_string(OBJ, v)
  326. END FUNCTION
  327.  
  328. ' Returns a pointer to the string stored in `v7_val_t`
  329. ' Returns NULL `undef` if the value is not a string or
  330. ' if the string is not compatible with a C string
  331. FUNCTION GET_CSTRING(v)
  332.   GET_CSTRING = js_get_cstring(OBJ, v)
  333. END FUNCTION
  334.  
  335. ' Make an empty object
  336. FUNCTION MK_OBJECT
  337.   MK_OBJECT = js_mk_object(OBJ)
  338. END FUNCTION
  339.  
  340. ' Returns true if the given value is an object or function
  341. FUNCTION IS_OBJECT(v)
  342.   IS_OBJECT = js_is_object(v)
  343. END FUNCTION
  344.  
  345. ' Get object's prototype.
  346. FUNCTION GET_PROTO(object)
  347.   GET_PROTO = js_get_proto(OBJ, object)
  348. END FUNCTION
  349.  
  350. ' Set object's prototype. Return old prototype or undefined on error
  351. FUNCTION SET_PROTO(object, proto)
  352.   SET_PROTO = js_set_proto(OBJ, object, proto)
  353. END FUNCTION
  354.  
  355. ' Lookup property `name` in object `obj`. If `obj` holds no such property,
  356. ' an `undefined` value is returned
  357. FUNCTION GETS(object, objname)
  358.   GETS = js_get(OBJ, object, objname, LEN(objname))
  359. END FUNCTION
  360.  
  361. ' Define object property, similar to JavaScript `Object.defineProperty()`
  362. FUNCTION DEF(object, objname, attr, value)
  363.   DEF = js_def(OBJ, object, objname, LEN(objname), attr, value)
  364. END FUNCTION
  365.  
  366. ' Set object property. Behaves just like JavaScript assignment
  367. FUNCTION SETS(object, objname, value)
  368.   SETS = js_set(OBJ, object, objname, LEN(objname), value)
  369. END FUNCTION
  370.  
  371. ' Delete own property `name` of the object `obj`
  372. ' Does not follow the prototype chain
  373. FUNCTION DEL(object, objname)
  374.   DEL = js_del(OBJ, object, objname, LEN(objname))
  375. END FUNCTION
  376.  
  377. ' Returns true if the object is an instance of a given constructor / class name
  378. FUNCTION IS_INSTANCEOF(object, classname)
  379.   IS_INSTANCEOF = js_is_instanceof(OBJ, object, classname)
  380. END FUNCTION
  381.  
  382. ' Returns true if the object is an instance of a given constructor object class
  383. FUNCTION IS_INSTANCEOF_V(object, objclass)
  384.   IS_INSTANCEOF_V = js_is_instanceof_v(OBJ, object, objclass)
  385. END FUNCTION
  386.  
  387. ' Custom multi-property `GET` function
  388. FUNCTION GET_PROPERTIES(object, proparray)
  389.   LOCAL objname, value, attr, propcnt
  390.   objname = ""
  391.   value = 0
  392.   attr = 0
  393.   propcnt = 1
  394.  ' UNDEF proparray
  395.  js_init_prop_iter_ctx(OBJ, object)
  396.   WHILE js_next_prop(OBJ, objname, value, attr) <> undef
  397.     proparray[propcnt, 0] = js_get_string(OBJ, objname)
  398.     proparray[propcnt, 1] = js_get_int(OBJ, value)
  399.     proparray[propcnt, 2] = attr
  400.     propcnt += 1
  401.   WEND
  402.   js_destruct_prop_iter_ctx(OBJ)
  403.   GET_PROPERTIES = propcnt - 1
  404. END FUNCTION
  405.  
  406. ' Make an empty array object
  407. FUNCTION MK_ARRAY
  408.   MK_ARRAY = js_mk_array(OBJ)
  409. END FUNCTION
  410.  
  411. ' Returns true if given value is an array object
  412. FUNCTION IS_ARRAY(object)
  413.   IS_ARRAY = js_is_array(OBJ, object)
  414. END FUNCTION
  415.  
  416. ' Returns length on an array. If `object` is not an array, 0 is returned
  417. FUNCTION ARRAY_LENGTH(object)
  418.   ARRAY_LENGTH = js_array_length(OBJ, object)
  419. END FUNCTION
  420.  
  421. ' Insert `value` in `object` at the end of the array
  422. FUNCTION ARRAY_PUSH(object, value)
  423.   ARRAY_PUSH = js_array_push(OBJ, object, value)
  424. END FUNCTION
  425.  
  426. '  Return array member at index `index`. If `index` is out of bounds, undefined is returned
  427. FUNCTION ARRAY_GET(object, index)
  428.   ARRAY_GET = js_array_get(OBJ, object, index)
  429. END FUNCTION
  430.  
  431. ' Insert value `v` into `arr` at 'index`
  432. FUNCTION ARRAY_SET(object, index, value)
  433.   ARRAY_SET = js_array_set(OBJ, object, index, value)
  434. END FUNCTION
  435.  
  436. ' Delete value in array `arr` at index `index`, if it exists
  437. SUB ARRAY_DEL(object, index)
  438.    js_array_del(OBJ, object, index)
  439. END SUB
  440.  
  441. ' Execute JavaScript `js_code`
  442. ' The result of evaluation is stored in the `return` variable
  443. ' The 'ok' argument will contain the function's execution success status flag
  444. FUNCTION EXEC(code, ok)
  445.   EXEC = js_exec(OBJ, code, ok)
  446. END FUNCTION
  447.  
  448. ' Same as `v7_exec()`, but loads source code from `path` file
  449. FUNCTION EXEC_FILE(codepath, ok)
  450.   EXEC_FILE = js_exec_file(OBJ, codepath, ok)
  451. END FUNCTION
  452.  
  453. ' Parse `json_code`
  454. ' The result of evaluation is stored in the `return` variable
  455. ' The 'ok' argument will contain the function's parse success status flag
  456. FUNCTION PARSE_JSON(json_code, ok)
  457.   PARSE_JSON = js_parse_json(OBJ, json_code, ok)
  458. END FUNCTION
  459.  
  460. ' Same as `v7_parse_json()`, but loads `json_code` from `path` file
  461. FUNCTION PARSE_JSON_FILE(json_code_file, ok)
  462.   PARSE_JSON_FILE = js_parse_json_file(OBJ, json_code_file, ok)
  463. END FUNCTION
  464.  
  465. ' Call function `func` with arguments `args`, using `object` as `this`
  466. ' `args` should be an array containing arguments or `undefined`
  467. FUNCTION APPLY(func, object, args)
  468.   APPLY = js_apply(OBJ, func, object, args)
  469. END FUNCTION
  470.  
  471. ' Make RegExp object. For example, `regex` is `(.+)`, `flags` is `gi`.
  472. FUNCTION MK_REGEXP(regex, flags, rcode)
  473.   MK_REGEXP = js_mk_regexp(OBJ, regex, LEN(regex), flags, LEN(flags), rcode)
  474. END FUNCTION
  475.  
  476. ' Returns true if given value is a JavaScript RegExp object
  477. FUNCTION IS_REGEXP(object)
  478.   IS_REGEXP = js_is_regexp(OBJ, object)
  479. END FUNCTION
  480.  
  481. ' Generate string representation of the JavaScript value
  482. FUNCTION STRINGIFY(object, convtype)
  483.   STRINGIFY = js_stringify(OBJ, object, convtype)
  484. END FUNCTION
  485.  
  486. ' Output a string representation of the value to stdout followed by a newline
  487. SUB PRINTIFY(object)
  488.   js_println(OBJ, object)
  489. END SUB
  490.  
  491.  
  492. END MODULE
  493.  


Hello JavaScript
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. JS::CREATE
  4. PRINT JS::GET_INT(JS::EXEC("1 + 1")),"\n"
  5. JS::DESTROY
  6.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_hello2.sb
2
jrs@jrs-laptop:~/sb/examples/js$


Fibonacci
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. jscode = """
  4. function fibonacci(n) {
  5.  if (n <= 2) {
  6.    return 1;
  7.  } else {
  8.    return fibonacci(n - 1) + fibonacci(n - 2);
  9.  }
  10. }
  11.  
  12. print(fibonacci(24));
  13. """
  14.  
  15. JS::CREATE
  16. JS::EXEC(jscode)
  17. JS::DESTROY
  18.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_fibonacci.sb
46368
jrs@jrs-laptop:~/sb/examples/js$


Create object, property and attributes
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. JS::CREATE
  4. myobj = JS::MK_OBJECT()
  5. JS::DEF(myobj, "test", 0, JS::MK_NUMBER(64))
  6. JS::SETS(myobj, "test", JS::MK_NUMBER(32))
  7. JS::DEF(myobj, "test", JS::WRITABLE(FALSE) OR JS::PRESERVE_VALUE(),JS::MK_NULL())
  8. JS::SETS(myobj, "test", JS::MK_NUMBER(16))
  9. PRINT "test = ",JS::GET_INT(JS::GETS(myobj, "test")),"\n"
  10. JS::DESTROY
  11.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_deftest.sb
test = 32
jrs@jrs-laptop:~/sb/examples/js$


Load .js file and get properties
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. JS::CREATE
  4. JS::EXEC_FILE "properties.js"
  5. propcnt = JS::GET_PROPERTIES(JS::GETS(JS::SYS,"test"), proparray)
  6. PRINT "Property\tValue\tAttribute\n"
  7. FOR i = 1 to propcnt
  8.   PRINT proparray[i,0],"\t\t",proparray[i,1],"\t",proparray[i,2],"\n"
  9. NEXT
  10. JS::DESTROY
  11.  

properties.js
Code: Javascript
  1. var test = {};
  2.  
  3. Object.defineProperty(test, 'a', {
  4.   value: 1,
  5.   writable: true,
  6.   enumerable: true,
  7.   configurable: true
  8. });
  9.  
  10. Object.defineProperty(test, 'b', {
  11.   value: 2,
  12.   writable: false,
  13.   enumerable: false,
  14.   configurable: false
  15. });
  16.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_propfile.sb
Property   Value   Attribute
b      2   7
a      1   0
jrs@jrs-laptop:~/sb/examples/js$


Call JavaScript function
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. jscode = """
  4. var sum = function(a, b, c) {
  5.  print (c);
  6.  return a + b; };
  7. """
  8.  
  9. JS::CREATE()
  10. JS::EXEC(jscode)
  11. func = JS::GETS(JS::SYS, "sum")
  12. args = JS::MK_ARRAY()
  13. JS::ARRAY_PUSH(args, JS::MK_NUMBER(123.0))
  14. JS::ARRAY_PUSH(args, JS::MK_NUMBER(0.456))
  15. JS::ARRAY_PUSH(args, JS::MK_STRING("Script BASIC"))
  16. result = JS::APPLY(func, 0, args, rcode)
  17. PRINT FORMAT("Result: %g\n", JS::GET_DOUBLE(result))
  18. JS::DESTROY
  19.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_callfunc.sb
Script BASIC
Result: 123.456
jrs@jrs-laptop:~/sb/examples/js$


JSON / Stringify
Code: Script BASIC
  1. IMPORT js.inc
  2.  
  3. JS::CREATE
  4. myobj = JS::MK_OBJECT()
  5. JS::DEF(myobj, "myprop_1", 0, JS::MK_NUMBER(64))
  6. JS::DEF(myobj, "myprop_2", 0, JS::MK_NUMBER(1.23))
  7. JS::DEF(myobj, "myprop_3", 0, JS::MK_STRING("JavaScript"))
  8. PRINT JS::STRINGIFY(myobj, JS::JSON),"\n"
  9. JS::DESTROY
  10.  


jrs@jrs-laptop:~/sb/examples/js$ scriba js_stringify.sb
{"myprop_3":"JavaScript","myprop_2":1.23,"myprop_1":64}
jrs@jrs-laptop:~/sb/examples/js$


FYI: - A Windows 32 bit version may materialize if I can get by the unexplainable issues on this platform. Windows isn't generally supported by Cesanta.


68
General Discussions / Re: module NT
« on: November 15, 2016, 09:24:52 PM »
I'm curious if you ran your test registry script as admin would you get the same results?

69
Installation / Re: Segmentation Fault.
« on: November 12, 2016, 05:26:18 PM »
I'm glad you got it running.

Have fun!

70
Installation / Re: Segmentation Fault.
« on: November 12, 2016, 03:41:47 PM »
My localhost Apache / sbhttpd proxy setup is working fine on my box. Here is my basic.conf and Apache 000-default.conf proxy settings.

Script BASIC Config

dll ".so"
module "/home/jrs/sb/sb22/modules/"
include "/home/jrs/sb/sb22/include/"
maxinclude 100
maxstep 0
maxlocalstep 0
maxlevel 29666
maxmem 0
servers (
  server (
    port 8889
    ip "127.0.0.1"
    protocol "http"
   )
  threads 20
  listenbacklog 3
  home "/home/jrs/sbweb/"
  proxyip 1
  pid (
    file "/home/jrs/sblog/pid.txt"
    delay 10
    wait (
      period 10
      length 1
     )
   )
  errmsgdest 3
  nolog 0
  log (
    panic (
      file "/home/jrs/sblog/panic.log"
     )
    app (
      file "/home/jrs/sblog/app.log"
     )
    err (
      file "/home/jrs/sblog/err.log"
     )
    hit (
      file "/home/jrs/sblog/hit.log"
     )
    stat (
      file "/home/jrs/sblog/stat.log"
     )
   )
  msg404 """
<HTML>
<HEAD>
<TITLE>Error 404 page not found</TITLE>
</HEAD>
<BODY>
<FONT FACE=\"Verdana\" SIZE=\"2\">
<H1>Page not found</H1>
We regretfully inform you that the page you have requested can not be found on this server.
<p>
In case you are sure that this is a server configuration error, please contact
<FONT SIZE=\"3\"><TT>root@localhost</TT></FONT>
</FONT>
</BODY>
</HTML>
 """
  code404 "200 OK"
 )


Apache

ProxyRequests Off
ProxyPass /home/ http://127.0.0.1:8889/
ProxyPassReverse /home/ http://127.0.0.1:8889/


sudo sbhttpd -start

I have found that the configuration file's default location assumed is /ect/scriba/.

Attached is my working Linux 64 bit sbhttpd.

71
Installation / Re: Segmentation Fault.
« on: November 12, 2016, 11:57:32 AM »
SBHTTPD is a HTTP web server that is usually a proxy to Apache as SBHTTPD doesn't handle media, only BASIC scripts. You need to access the SBHTTPD sever via a web browser.

Please post the configuration you are using now and I will help you try to straighten out.

72
General Discussions / Re: EXECUTE error handle
« on: November 11, 2016, 07:25:50 PM »
I have noticed that (0): error &H1:Not enough memory is used as a catch all error message.

Thanks for the heads up! I'll have a peek at the code and see if I can make that error code more relevant.





73
General Discussions / Re: convert epoch time
« on: October 25, 2016, 01:59:21 PM »
Like I said, Script BASIC only has 1 second resolution. The number you're getting back from NOW or GMTIME is seconds past Jan. 1, 1970 00:00 AM. You need to do milliseconds function in an extension module like I did with SDL_gfx or IMPORT it.



74
General Discussions / Re: convert epoch time
« on: October 25, 2016, 12:40:32 AM »
Script BASIC only has a resolution of 1 second. I created a millisecond resolution timer using the SDL_gfx extension module.

75
General Discussions / Re: convert epoch time
« on: October 24, 2016, 12:37:34 PM »
Code: Script BASIC
  1. FormatDate("format",time)
  2.  

Arguments

format is a string using the formatting characters described in the docs.

time can be NOW or any other number of seconds past Jan. 1, 1970.

It's really easy to do date math in Script BASIC.

Pages: 1 ... 3 4 [5] 6 7 ... 59