Sfoglia il codice sorgente

Update sqlite3 and some examples.

mingodad 11 anni fa
parent
commit
a51df3bdc3

File diff suppressed because it is too large
+ 325 - 145
SquiLu-ext/sqlite3.c


+ 95 - 66
SquiLu-ext/sqlite3.h

@@ -57,7 +57,7 @@ extern "C" {
 /*
 ** These no-op macros are used in front of interfaces to mark those
 ** interfaces as either deprecated or experimental.  New applications
-** should not use deprecated interfaces - they are support for backwards
+** should not use deprecated interfaces - they are supported for backwards
 ** compatibility only.  Application writers should be aware that
 ** experimental interfaces are subject to change in point releases.
 **
@@ -109,7 +109,7 @@ extern "C" {
 */
 #define SQLITE_VERSION        "3.8.8"
 #define SQLITE_VERSION_NUMBER 3008008
-#define SQLITE_SOURCE_ID      "2014-11-05 21:34:56 272fddc14cc322655eeba670bc0f9fc30e5a804c"
+#define SQLITE_SOURCE_ID      "2014-11-20 02:58:10 2d7c8da5f16e64eaa7b0c2d66898682ea3d102a0"
 
 /*
 ** CAPI3REF: Run-Time Library Version Numbers
@@ -1599,14 +1599,16 @@ struct sqlite3_mem_methods {
 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer 
 ** that SQLite will use for all of its dynamic memory allocation needs
 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
+** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
+** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
+** [SQLITE_ERROR] if invoked otherwise.
 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
 ** An 8-byte aligned pointer to the memory,
 ** the number of bytes in the memory buffer, and the minimum allocation size.
 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
 ** to using its default memory allocator (the system malloc() implementation),
 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
-** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
-** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
+** memory pointer is not NULL then the alternative memory
 ** allocator is engaged to handle all of SQLites memory allocation needs.
 ** The first pointer (the memory pointer) must be aligned to an 8-byte
 ** boundary or subsequent behavior of SQLite will be undefined.
@@ -1736,8 +1738,8 @@ struct sqlite3_mem_methods {
 ** ^The default setting can be overridden by each database connection using
 ** either the [PRAGMA mmap_size] command, or by using the
 ** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
-** cannot be changed at run-time.  Nor may the maximum allowed mmap size
-** exceed the compile-time maximum mmap size set by the
+** will be silently truncated if necessary so that it does not exceed the
+** compile-time maximum mmap size set by the
 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
 ** ^If either argument to this option is negative, then that argument is
 ** changed to its compile-time default.
@@ -4198,9 +4200,9 @@ SQLITE_API int sqlite3_create_function_v2(
 ** These constant define integer codes that represent the various
 ** text encodings supported by SQLite.
 */
-#define SQLITE_UTF8           1
-#define SQLITE_UTF16LE        2
-#define SQLITE_UTF16BE        3
+#define SQLITE_UTF8           1    /* IMP: R-37514-35566 */
+#define SQLITE_UTF16LE        2    /* IMP: R-03371-37637 */
+#define SQLITE_UTF16BE        3    /* IMP: R-51971-34154 */
 #define SQLITE_UTF16          4    /* Use native byte order */
 #define SQLITE_ANY            5    /* Deprecated */
 #define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
@@ -5696,26 +5698,42 @@ typedef struct sqlite3_blob sqlite3_blob;
 **     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
 ** </pre>)^
 **
+** ^(Parameter zDb is not the filename that contains the database, but 
+** rather the symbolic name of the database. For attached databases, this is
+** the name that appears after the AS keyword in the [ATTACH] statement.
+** For the main database file, the database name is "main". For TEMP
+** tables, the database name is "temp".)^
+**
 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
-** and write access. ^If it is zero, the BLOB is opened for read access.
-** ^It is not possible to open a column that is part of an index or primary 
-** key for writing. ^If [foreign key constraints] are enabled, it is 
-** not possible to open a column that is part of a [child key] for writing.
-**
-** ^Note that the database name is not the filename that contains
-** the database but rather the symbolic name of the database that
-** appears after the AS keyword when the database is connected using [ATTACH].
-** ^For the main database file, the database name is "main".
-** ^For TEMP tables, the database name is "temp".
-**
-** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
-** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
-** to be a null pointer.)^
-** ^This function sets the [database connection] error code and message
-** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
-** functions. ^Note that the *ppBlob variable is always initialized in a
-** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
-** regardless of the success or failure of this routine.
+** and write access. ^If the flags parameter is zero, the BLOB is opened for
+** read-only access.
+**
+** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
+** in *ppBlob. Otherwise an [error code] is returned and, unless the error
+** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
+** the API is not misused, it is always safe to call [sqlite3_blob_close()] 
+** on *ppBlob after this function it returns.
+**
+** This function fails with SQLITE_ERROR if any of the following are true:
+** <ul>
+**   <li> ^(Database zDb does not exist)^, 
+**   <li> ^(Table zTable does not exist within database zDb)^, 
+**   <li> ^(Table zTable is a WITHOUT ROWID table)^, 
+**   <li> ^(Column zColumn does not exist)^,
+**   <li> ^(Row iRow is not present in the table)^,
+**   <li> ^(The specified column of row iRow contains a value that is not
+**         a TEXT or BLOB value)^,
+**   <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE 
+**         constraint and the blob is being opened for read/write access)^,
+**   <li> ^([foreign key constraints | Foreign key constraints] are enabled, 
+**         column zColumn is part of a [child key] definition and the blob is
+**         being opened for read/write access)^.
+** </ul>
+**
+** ^Unless it returns SQLITE_MISUSE, this function sets the 
+** [database connection] error code and message accessible via 
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 
+**
 **
 ** ^(If the row that a BLOB handle points to is modified by an
 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
@@ -5733,13 +5751,9 @@ typedef struct sqlite3_blob sqlite3_blob;
 ** interface.  Use the [UPDATE] SQL command to change the size of a
 ** blob.
 **
-** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
-** table.  Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
-**
 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
-** and the built-in [zeroblob] SQL function can be used, if desired,
-** to create an empty, zero-filled blob in which to read or write using
-** this interface.
+** and the built-in [zeroblob] SQL function may be used to create a 
+** zero-filled blob to read or write using the incremental-blob interface.
 **
 ** To avoid a resource leak, every open [BLOB handle] should eventually
 ** be released by a call to [sqlite3_blob_close()].
@@ -5781,24 +5795,22 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_i
 /*
 ** CAPI3REF: Close A BLOB Handle
 **
-** ^Closes an open [BLOB handle].
-**
-** ^Closing a BLOB shall cause the current transaction to commit
-** if there are no other BLOBs, no pending prepared statements, and the
-** database connection is in [autocommit mode].
-** ^If any writes were made to the BLOB, they might be held in cache
-** until the close operation if they will fit.
-**
-** ^(Closing the BLOB often forces the changes
-** out to disk and so if any I/O errors occur, they will likely occur
-** at the time when the BLOB is closed.  Any errors that occur during
-** closing are reported as a non-zero return value.)^
+** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
+** unconditionally.  Even if this routine returns an error code, the 
+** handle is still closed.)^
 **
-** ^(The BLOB is closed unconditionally.  Even if this routine returns
-** an error code, the BLOB is still closed.)^
+** ^If the blob handle being closed was opened for read-write access, and if
+** the database is in auto-commit mode and there are no other open read-write
+** blob handles or active write statements, the current transaction is
+** committed. ^If an error occurs while committing the transaction, an error
+** code is returned and the transaction rolled back.
 **
-** ^Calling this routine with a null pointer (such as would be returned
-** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
+** Calling this function with an argument that is not a NULL pointer or an
+** open blob handle results in undefined behaviour. ^Calling this routine 
+** with a null pointer (such as would be returned by a failed call to 
+** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
+** is passed a valid open blob handle, the values returned by the 
+** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 */
 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
 
@@ -5848,21 +5860,27 @@ SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 /*
 ** CAPI3REF: Write Data Into A BLOB Incrementally
 **
-** ^This function is used to write data into an open [BLOB handle] from a
-** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
-** into the open BLOB, starting at offset iOffset.
+** ^(This function is used to write data into an open [BLOB handle] from a
+** caller-supplied buffer. N bytes of data are copied from the buffer Z
+** into the open BLOB, starting at offset iOffset.)^
+**
+** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
+** Otherwise, an  [error code] or an [extended error code] is returned.)^
+** ^Unless SQLITE_MISUSE is returned, this function sets the 
+** [database connection] error code and message accessible via 
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 
 **
 ** ^If the [BLOB handle] passed as the first argument was not opened for
 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
 ** this function returns [SQLITE_READONLY].
 **
-** ^This function may only modify the contents of the BLOB; it is
+** This function may only modify the contents of the BLOB; it is
 ** not possible to increase the size of a BLOB using this API.
 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
-** [SQLITE_ERROR] is returned and no data is written.  ^If N is
-** less than zero [SQLITE_ERROR] is returned and no data is written.
-** The size of the BLOB (and hence the maximum value of N+iOffset)
-** can be determined using the [sqlite3_blob_bytes()] interface.
+** [SQLITE_ERROR] is returned and no data is written. The size of the 
+** BLOB (and hence the maximum value of N+iOffset) can be determined 
+** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less 
+** than zero [SQLITE_ERROR] is returned and no data is written.
 **
 ** ^An attempt to write to an expired [BLOB handle] fails with an
 ** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
@@ -5871,9 +5889,6 @@ SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 ** have been overwritten by the statement that expired the BLOB handle
 ** or by other independent statements.
 **
-** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
-** Otherwise, an  [error code] or an [extended error code] is returned.)^
-**
 ** This routine only works on a [BLOB handle] which has been created
 ** by a prior successful call to [sqlite3_blob_open()] and which has not
 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
@@ -6874,6 +6889,10 @@ typedef struct sqlite3_backup sqlite3_backup;
 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
 ** an error.
 **
+** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if 
+** there is already a read or read-write transaction open on the 
+** destination database.
+**
 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
 ** returned and an error code and error message are stored in the
 ** destination [database connection] D.
@@ -7481,13 +7500,15 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
 **
 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
-** total number of rows visited by the X-th loop.</dd>
+** total number of rows examined by all iterations of the X-th loop.</dd>
 **
 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set to the
-** query planner's estimate for the number of rows visited for each
-** iteration of the X-th loop.  If the query planner's estimate was accurate,
-** then this value should be approximately NVISIT/NLOOP.
+** <dd>^The "double" variable pointed to by the T parameter will be set to the
+** query planner's estimate for the average number of rows output from each
+** iteration of the X-th loop.  If the query planner's estimates was accurate,
+** then this value will approximate the quotient NVISIT/NLOOP and the
+** product of this value for all prior loops with the same SELECTID will
+** be the NLOOP value for the current loop.
 **
 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to 
@@ -7498,6 +7519,13 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
 ** <dd>^The "const char *" variable pointed to by the T parameter will be set to 
 ** a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] description
 ** for the X-th loop.
+**
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
+** <dd>^The "int" variable pointed to by the T parameter will be set to the
+** "select-id" for the X-th loop.  The select-id identifies which query or
+** subquery the loop is part of.  The main query has a select-id of zero.
+** The select-id is the same value as is output in the first column
+** of an [EXPLAIN QUERY PLAN] query.
 ** </dl>
 */
 #define SQLITE_SCANSTAT_NLOOP    0
@@ -7505,6 +7533,7 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
 #define SQLITE_SCANSTAT_EST      2
 #define SQLITE_SCANSTAT_NAME     3
 #define SQLITE_SCANSTAT_EXPLAIN  4
+#define SQLITE_SCANSTAT_SELECTID 5
 
 /*
 ** CAPI3REF: Prepared Statement Scan Status

+ 13 - 13
SquiLu-ourbiz/EvaLayoutManager.nut

@@ -100,7 +100,7 @@ class EvaLayoutManager
 	
 	function setLayout (layoutInfo)
 	{
-		if(type(layoutInfo) === "string")
+		if(type(layoutInfo) == "string")
 		{
 			var linfo = [];
 			var lines = layoutInfo.split('\n');
@@ -110,7 +110,7 @@ class EvaLayoutManager
 			{
 				var rec = lines[i].split(',');
 				var rec_len = rec.len();
-				if(rec_len === 1) continue; //ignore blank lines
+				if(rec_len == 1) continue; //ignore blank lines
 				for(var j=0; j < rec_len; ++j)
 				{
 					rec[j] = rec[j].strip();
@@ -199,7 +199,7 @@ class EvaLayoutManager
 		var arsize = aryReparto.len();
 		var totalWeight = 0;
 		for (var ii = 0; ii < arsize; ii ++) totalWeight += aryReparto[ii][1];
-		var repartHV = totalReparto / ((totalWeight === 0) ? 1 : totalWeight);
+		var repartHV = totalReparto / ((totalWeight == 0) ? 1 : totalWeight);
 		for (var ii = 0; ii < arsize; ii ++)
 		{
 			var colAry = aryReparto[ii];
@@ -242,12 +242,12 @@ class EvaLayoutManager
 			var mm;
 			for (mm = indxPosLeft; mm <= indxPosRight; mm ++)
 			{
-				if (mm !== indxPosLeft) dx += Hgap;
+				if (mm != indxPosLeft) dx += Hgap;
 				dx += Hdim[mm];
 			}
 			for (mm = indxPosTop; mm <= indxPosBottom; mm ++)
 			{
-				if (mm !== indxPosTop) dy += Vgap;
+				if (mm != indxPosTop) dy += Vgap;
 				dy += Vdim[mm];
 			}
 
@@ -331,7 +331,7 @@ class EvaLayoutManager
 	function isExpandWeight (headStr, aryToStore, idxToStore)
 	{
 		var strLen = headStr.len() ;
-		if (strLen && headStr[0] === HEADER_EXPAND[0])
+		if (strLen && headStr[0] == HEADER_EXPAND[0])
 		{
 			var weight = 1;
 			if(strLen > 1)
@@ -351,7 +351,7 @@ class EvaLayoutManager
 		for (var rr = 0; rr < nrcsize; rr ++)
 		{
 			var heaStr = getHeader(rr);
-			var gap = (rr === 0) ? 0 : VHgap;
+			var gap = (rr == 0) ? 0 : VHgap;
 
 			VHdim.push (0);
 			VHpos.push (0);
@@ -359,7 +359,7 @@ class EvaLayoutManager
 
 			if (!isExpandWeight(heaStr, aryReparto, rr))
 			{
-				if (heaStr === "" || heaStr === HEADER_ADAPT)
+				if (heaStr == "" || heaStr == HEADER_ADAPT)
 				{
 					VHdim[rr] = getMinOf(rr);   // maximum-minimum of the row
 				}
@@ -419,7 +419,7 @@ class EvaLayoutManager
 				var name = widgetAt(rr, cc);
 
 				var indx = indxComponent (name);
-				if (indx === -1) continue;
+				if (indx == -1) continue;
 
 				var wid = componentArray[indx];
 				var indxPos = wid.indxPos;
@@ -430,11 +430,11 @@ class EvaLayoutManager
 
 				// set position x2,y2
 				var ava = cc;
-				while (ava+1 < ncsize && widgetAt(rr, ava+1) === EXPAND_HORIZONTAL) ava ++;
+				while (ava+1 < ncsize && widgetAt(rr, ava+1) == EXPAND_HORIZONTAL) ava ++;
 				indxPos.right = ava;
 
 				ava = rr;
-				while (ava+1 < nrsize && widgetAt(ava+1, cc) === EXPAND_VERTICAL) ava ++;
+				while (ava+1 < nrsize && widgetAt(ava+1, cc) == EXPAND_VERTICAL) ava ++;
 				indxPos.bottom = ava;
 
 				wid.isLaidOut = true;
@@ -500,7 +500,7 @@ class EvaLayoutManager
 	};
 }
 
-class MyEvaLayoutManager extends EvaLayoutManager {
+class FltkEvaLayoutManager extends EvaLayoutManager {
 	function showComponent(cId, bShowHide)
 	{
 		//print("show", cId, bShowHide);
@@ -531,7 +531,7 @@ var layInfo = [
 	[  "A"   ,  "edit1"     ,   "-"        , "boton4" ],
 ];
 
-var manager = new MyEvaLayoutManager();
+var manager = new FltkEvaLayoutManager();
 manager.setLayout(layInfo);
 
 class EvaWindow extends Fl_Window {

+ 166 - 20
SquiLu-ourbiz/companies-uk.nut

@@ -14,7 +14,9 @@ local function getCompaniesUkDBFileName(){
 	if (globals.rawget("jniLog", false)) return APP_CODE_FOLDER + "/companies-uk-RG.db";
 	if (globals.rawget("WIN32", false)) return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-RG.db";
 	//return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-RG.db";
-	return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-2013-10.db";
+	//return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-RG-2014-07.db";
+	//return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-2013-10.db";
+	return APP_CODE_FOLDER + "/../../companies-uk/companies-uk-2014-07.db";
 }
 
 local companiesUkDB = null;
@@ -43,23 +45,28 @@ local function getCachedStmt(stmt_key, sql_or_func){
 
 
 local function getCiaUkSearchList(search_str, search_post_code, search_sic_code,
-			search_origin_post_code, search_around_post_code , sic_street, page, limit){
+			search_origin_post_code, search_around_post_code , sic_street, page, limit, search_extra_info){
 	local offset = page * limit;
 	local post_code_radius = strHasContent(search_around_post_code) ? search_around_post_code.tointeger() : 0;
 	local stmt, stmt_count, bind_str;
 	local hasSicSearch = false;
 	local bind_names;
 	local base_sql = "select c.id, c.number, c.name, round((julianday('now') - julianday(incorporation_date)) / 354, 1) as age, c.post_code from companies  c "
-	//debug_print(search_str or "nil", "\t",search_post_code or "nil", "\t", search_sic_code or "nil", "\t", page, "\n")
+	//debug_print(search_str || "nil", "\t",search_post_code || "nil", "\t", search_sic_code || "nil", "\t", page, "\n")
 	//print(search_str, search_post_code, search_sic_code, search_origin_post_code, search_around_post_code , page, limit)
 	//print("AtLine:", __LINE__)
 
 	if (strHasContent(search_str) && search_str.find_lua("%d+") == 0){
-		bind_str1 = search_str;
+		bind_str = search_str;
 		limit = 0;
 		stmt = getCachedStmt("getCiaUkSearchList1", @() format(" %s where c.number = ?", base_sql));
 	}
+	/*
+	else if (strHasContent(search_extra_info) ){
+	}
+	*/
 	else if (post_code_radius > 0 && strHasContent(search_origin_post_code)){
+
 		local sic_codes_sql = "";
 		local sic_code = null;
 		local cached_stmt_name = "";
@@ -74,6 +81,7 @@ and c.post_code = pc.post_code
 limit :limit offset :offset
 ]==];
 		if (strHasContent(search_sic_code)){
+
 			if (search_sic_code.find_lua("%d+") == 0){
 				sic_codes_sql = "and c.id in(select company_id from companies_sic_codes where sic_code like :sic_code)";
 				sic_code = search_sic_code + "%";
@@ -95,6 +103,7 @@ limit :limit offset :offset
 		if (sic_code) bind_names.sic_code <- sic_code;
 	}
 	else if (strHasContent(search_str) && strHasContent(search_post_code)){
+
 		stmt = getCachedStmt("getCiaUkSearchList4", @() format([==[
 %s, companies_fts cf
 where companies_fts match ?
@@ -105,6 +114,7 @@ limit ? offset ?
 		bind_str = format("name:%s post_code:%s", search_str, search_post_code);
 	}
 	else if (strHasContent(search_post_code)){
+
 		if (strHasContent(search_sic_code)){
 			hasSicSearch = true;
 			local sic_code_sql;
@@ -144,6 +154,7 @@ limit ? offset ?
 		bind_str = format("post_code:%s*", search_post_code);
 	}
 	else if ( (!strHasContent(search_str)) && (!strHasContent(search_post_code)) && strHasContent(search_sic_code)) {
+
 		if (sic_street && sic_street == "street"){
 			search_sic_code = "%" + search_sic_code + "%";
 			stmt = getCachedStmt("getCiaUkSearchList8", "select distinct id, address, post_code from companies where address like ? order by 2 limit ? offset ?");
@@ -160,6 +171,7 @@ limit ? offset ?
 	}
 	else
 	{
+
 		bind_str = search_str;
 		stmt = getCachedStmt("getCiaUkSearchList11", @() format([==[
 %s, companies_fts cf
@@ -172,6 +184,7 @@ limit ? offset ?
 	local xp = 1;
 	stmt.reset();
 //debug_print("\n", bind_str, ":", limit, ":", offset);
+//debug_print("\n", stmt.get_sql(), " == ", limit, ":", offset);
 	if (bind_names) stmt.bind_names(bind_names);
 	else
 	{
@@ -238,7 +251,14 @@ and ref.post_code = ?
 		}
 		//stmt.reset();
 		stmt.finalize();
-		rows.sort(@(a,b) (a[6] || 0) <=> (b[6] || 0));
+		//rows.sort(@(a,b) (a[6] || 0) <=> (b[6] || 0));
+		rows.sort(@(a,b) (a[5] || 0) <=> (b[5] || 0));
+/*
+		foreach( k,v in rows) {
+			foreach(zk, zv in v) debug_print(zk.tostring(), ":", zv);
+			debug_print("\n");
+		}
+*/
 	}
 }
 
@@ -293,21 +313,32 @@ local function osGridToLatLong(easting, northing){
 
   local lat=lat0;
   local M=0.0;
+  
+  local ma_p1 = (1.0 + n + (5.0/4.0)*n2 + (5.0/4.0)*n3);
+  local mb_p1 = (3.0*n + 3.0*n2 + (21.0/8.0)*n3);
+  local mc_p1 = ((15.0/8.0)*n2 + (15.0/8.0)*n3);
+  local md_p1 = (35.0/24.0)*n3;
+  local n_less_n0 = N-N0;
+  local bf0 = b * F0;
+  local af0 = a * F0;
+  
   do {
-    lat = (N-N0-M)/(a*F0) + lat;
-
-    local Ma = (1.0 + n + (5.0/4.0)*n2 + (5.0/4.0)*n3) * (lat-lat0);
-    local Mb = (3.0*n + 3.0*n*n + (21.0/8.0)*n3) * sin(lat-lat0) * cos(lat+lat0);
-    local Mc = ((15.0/8.0)*n2 + (15.0/8.0)*n3) * sin(2*(lat-lat0)) * cos(2*(lat+lat0));
-    local Md = (35.0/24.0)*n3 * sin(3.0*(lat-lat0)) * cos(3*(lat+lat0));
-    M = b * F0 * (Ma - Mb + Mc - Md);                // meridional arc
+    lat = (n_less_n0-M)/af0 + lat;  
+    local lat_less_lat0 =  lat-lat0;
+    local lat_plus_lat0 =  lat+lat0;
+    local Ma =  ma_p1 * lat_less_lat0;
+    local Mb =  mb_p1 * sin(lat_less_lat0) * cos(lat_plus_lat0);
+    local Mc =  mc_p1 * sin(2*lat_less_lat0) * cos(2*lat_plus_lat0);
+    local Md =  md_p1 * sin(3.0*lat_less_lat0) * cos(3*lat_plus_lat0);
+    M = bf0 * (Ma - Mb + Mc - Md);                // meridional arc
 
-  } while (N-N0-M >= 0.00001);  // ie until < 0.01mm
+  } while (n_less_n0-M >= 0.00001);  // ie until < 0.01mm
 
   local cosLat = cos(lat);
   local sinLat = sin(lat);
-  local nu = a*F0/math.sqrt(1.0-e2*sinLat*sinLat);              // transverse radius of curvature
-  local rho = a*F0*(1.0-e2)/math.pow(1.0-e2*sinLat*sinLat, 1.5);  // meridional radius of curvature
+  local e2_sinLat2 = 1.0-e2*sinLat*sinLat;
+  local nu = a*F0/math.sqrt(e2_sinLat2);              // transverse radius of curvature
+  local rho = a*F0*(1.0-e2)/math.pow(e2_sinLat2, 1.5);  // meridional radius of curvature
   local eta2 = nu/rho-1.0;
 
   local tanLat = math.tan(lat);
@@ -383,7 +414,56 @@ local function downloadChunked(host, file, extra_header=null){
 	return data.concat("\n");
 }
 
-local function getExtraCompanyDataOnNet(cnum){
+local function downloadChunked2(host, file, extra_header=null){
+	local sock = socket.tcp();
+	sock.settimeout(1000);
+	sock.connect(host, 80);
+
+	local count = 0;    // counts number of bytes read
+	local req;
+	if (extra_header) req = extra_header;
+	else req = format("GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", file, host);
+
+	//print("REQUEST:", req)
+	sock.send(req);
+	local rc, s;
+	local data = [];
+
+	// load header
+	while (true){
+		rc = sock.receive("*l");
+		s = rc[0];
+		//print("s", s, rc[1]);
+		//if err == "closed" then break end
+		if (s.len() == 0) break;
+		//if (rc[1] == socket.IO_CLOSED) break;
+	}
+	
+	// load data
+	while (true){
+		rc = sock.receive("*l");
+		s = rc[0];
+		//print("s", s, rc[1]);
+		if (s.len() == 0) break;
+		local chunk_size = ("0x" + rc[0]).tointeger(16);
+		//print(chunk_size);
+		
+		rc = sock.receive(chunk_size);
+		if(rc[1] == socket.IO_CLOSED) break;
+		else if(rc[1] != socket.IO_DONE) throw (format("socket io error (%d)", rc[1]));
+		s = rc[0];
+		if (s.len() == 0){
+			break;
+		}
+		data.push(s);
+		rc = sock.receive("*l"); //eat the new line after chunk
+	}
+	sock.close();
+	//print(file, count)
+	return data.concat("");
+}
+
+local function getExtraCompanyDataOnNet0(cnum){
 	local mainHost = "wck2.companieshouse.gov.uk";
 
 	//get session
@@ -467,6 +547,29 @@ User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko)
 	return data;
 }
 
+local function getExtraCompanyDataOnNet(cnum){
+	local mainHost = "wck2.companieshouse.gov.uk";
+	local page = null;
+	try {
+		page = downloadChunked2(mainHost, "/api/filinghistory?q=" + cnum);
+	} catch(e){
+		if(e != "closed") throw e;
+	}
+	if (!page) return "";
+	
+	local data = json2var(page);
+	local tdata = [];
+	local results = data.rawget("results", []);
+	for(var i=0, len=results.len(); i < len; ++i)
+	{
+		local rec = results[i];
+		local line = rec.rawget("type", "") + "|" + rec.rawget("date", "") + "|" + rec.rawget("description", "");
+		line = line.gsub("\n", "\\n");
+		tdata.push( line );
+	}
+	return tdata.concat("\n");
+}
+
 local function getExtraCompanyData(cid, cnum){
 	local data;
 	local db = getCompaniesUkDB();
@@ -502,7 +605,7 @@ local my_uri_handlers = {
 		data.limit <- 25;
 		local query_string = request.info.query_string;
 		bool_t isPost = request.info.request_method == "POST";
-		local filed_names = ["search_str", "search_post_code", "search_origin_post_code",
+		local filed_names = ["search_str", "search_extra_info", "search_post_code", "search_origin_post_code",
 			"search_around_post_code", "search_sic_code", "sic_street", "page"];
 		if (isPost) {
 			local post_fields =  get_post_fields(request);
@@ -516,10 +619,11 @@ local my_uri_handlers = {
 		else data.page = data.page.tointeger();
 
 		local errcode;
-		if (strHasContent(data.search_str) || strHasContent(data.search_post_code) || strHasContent(data.search_sic_code)) {
+		if (strHasContent(data.search_str) || strHasContent(data.search_extra_info) || strHasContent(data.search_post_code) 
+				|| strHasContent(data.search_sic_code)) {
 			data.sicSearchResults <- strHasContent(data.search_sic_code) && !(strHasContent(data.search_str) || strHasContent(data.search_post_code))
 			local result = getCiaUkSearchList(data.search_str, data.search_post_code, data.search_sic_code,
-				data.search_origin_post_code, data.search_around_post_code , data.sic_street, data.page, data.limit);
+				data.search_origin_post_code, data.search_around_post_code , data.sic_street, data.page, data.limit, data.search_extra_info);
 
 			if (result[1] /*errcode*/ == SQLite3.SQLITE_INTERRUPT) {
 				data.queryWasInterrupted <- true;
@@ -564,7 +668,7 @@ local my_uri_handlers = {
 			}
 		}
 		local filed_names = ["search_str", "search_post_code", "search_origin_post_code",
-			"search_around_post_code", "search_sic_code", "sic_street", "page"];
+			"search_around_post_code", "search_sic_code", "sic_street", "page", "search_extra_info"];
 		foreach(k in filed_names) data[k] <- null;
 
 		//debug_tprint(data.company)
@@ -577,10 +681,52 @@ local my_uri_handlers = {
 		request.write_blob(mFile);
 		return true;
 	},
+	["/api/v2/companysearch"] = function(request){
+		local query_string = request.info.query_string;
+		if(!query_string) return false;
+		
+		local data = {};
+		data.limit <- 25;
+		local filed_names = ["search_str", "search_extra_info", "search_post_code", "search_origin_post_code",
+			"search_around_post_code", "search_sic_code", "sic_street", "page"];
+		foreach(k in filed_names) data[k] <-request.get_var(query_string, k);
+
+		data.page <- 0;
+		data.search_str <- request.get_var(query_string, "q");
+
+		local result = getCiaUkSearchList(data.search_str, data.search_post_code, data.search_sic_code,
+			data.search_origin_post_code, data.search_around_post_code , data.sic_street, data.page, data.limit, data.search_extra_info);
+
+		if (result[1] /*errcode*/ == SQLite3.SQLITE_INTERRUPT) {
+			data.queryWasInterrupted <- true;
+		}
+		
+
+		result = var2json(result[0]);
+		request.print(format("HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: %d\r\n\r\n", result.len()));
+		request.print(result);
+		return true;
+	},
+	["/hello"] = function(request){
+		local response = "<html><body>Hello World !</body></html>"
+		request.print(format("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: %d\r\n\r\n%s", response.len(), response));
+		return true;
+	},
 }
 
 add_uri_hanlders(my_uri_handlers);
 
+/*
+local function my_uri_filter(request)
+{
+	local request_uri = request.info.uri;
+	if(request_uri.startswith("/api/"))
+	{
+	}
+}
+add_uri_filters(my_uri_filter);
+*/
+
  ::MyCompaniesUkLoaded <- true;
 
 } //end dummy nested scope

+ 2 - 1
SquiLu-ourbiz/index.tpl

@@ -367,6 +367,7 @@ function sortTable(id, col, numeric){
 <form action="/#results" method="post" onsubmit="saveFormFields(this)" id="search_form">
 <table>
 <tr><td>Company Name</td><td><input type="text" name="search_str" value="<?=search_str?>" title="enter a company name to search"></td></tr>
+<tr><td>Extra info</td><td><input type="text" name="search_extra_info" value="<?=search_extra_info?>" title="enter extra info to search"></td></tr>
 <tr><td>Post Code</td><td><input type="text" name="search_post_code" value="<?=search_post_code?>" title="enter a complete or parcial post code"></td></tr>
 <tr><td><select name="sic_street"><option value="sic">SIC Code</option><option value="street">Street</option></select></td>
 <td><input type="text" name="search_sic_code" value="<?=search_sic_code?>" title="enter a complete or parcial sic code"></td></tr>
@@ -427,7 +428,7 @@ function sortTable(id, col, numeric){
 <table class="nj">
 <tr><th>Code</th><th>Description</th><th>#Companies</th></tr>
 <? foreach( k, rec in rows){ ?>
-<tr><td><a href="#search_form" onclick="setSicCode(<?=rec[1]?>)"><?=rec[1]?></a></td><td><?=rec[2]?></td><td><?=rec[3]?></td></tr>
+<tr><td><a href="#search_form" onclick="setSicCode(<?=rec[1]?>)"><?=rec[1]?></a></td><td><?=rec[2]?></td><td><?=rec.get(3, "")?></td></tr>
 <? }
 	page = page.tointeger();
 	local hasPrevious = page > 0;

+ 1 - 1
SquiLu-ourbiz/ourbiz.nut

@@ -3160,7 +3160,7 @@ Content-Length: %d
 		}
 
 		if (sql){
-			debug_print(sql, "\n", db.errmsg(), "\n")
+			//debug_print(sql, "\n", db.errmsg(), "\n")
 			local stmt = db.prepare(sql);
 			//debug_print(sql, "\n", db.errmsg(), "\n")
 			data = stmt.asSleArray();

+ 9 - 9
SquiLu-ourbiz/s/ourbiz/calendar-chooser.js

@@ -1,7 +1,7 @@
 Jaml.register('CalendarChooserWindow', function(args) {
 	var callOpFunc = "CalendarChooserSetDate('" + args.id + "','";
-	var callOp = function(op){return callOpFunc + op + "')";}
-	var cbtn = function() {return input({type:"button"});}
+	var callOp = function(op){return callOpFunc + op + "')";};
+	var cbtn = function() {return input({type:"button"});};
 	form({id: args.form_id, style: "width:100%;height:100%;", onsubmit:"return false;"},
 		table({style: "width:100%;", cls:"calTbl"},
 			tr(
@@ -75,7 +75,7 @@ function CalendarChooserMakemonth(y,m){
 	// get back to the nearest monday
 	adate.setTime(adate.getTime()-(DAY_MILISECONDS * (adate.getDay()-1)));
 	var day = adate.getDate();
-	if(day < 7 && day != 1){
+	if(day < 7 && day !== 1){
 		//go back one more week
 		adate.setTime(adate.getTime() - (DAY_MILISECONDS * 7));
 	}
@@ -85,8 +85,8 @@ function CalendarChooserMakemonth(y,m){
 		do { // insert the week days
 			weekArray.push(adate.getDate());
 			adate.setTime(adate.getTime() + DAY_MILISECONDS);
-		} while( adate.getDay() != 1 ) // monday
-	} while( adate.getMonth() == m );
+		} while( adate.getDay() !== 1 ) // monday
+	} while( adate.getMonth() === m );
 	return monthArray;
 }
 
@@ -139,7 +139,7 @@ function CalendarChooserFocusUpDown(elm, up){
 	for(var r=rows.length-1; r >= 0; --r){
 		var cells = rows[r].cells;
 		for(var c=cells.length-1; c >= 0; --c){
-			if(getFirstChild(cells[c]) == elm){
+			if(getFirstChild(cells[c]) === elm){
 				if(up){
 					if(r > 1){ //second row and bellow
 						getFirstChild(rows[r-1].cells[c]).focus();
@@ -181,7 +181,7 @@ function CalendarChooserInputOnKeydown(event){
 }	
 
 function newCalendarChooserWindow(){
-	var title = "Calendar Chooser"
+	var title = "Calendar Chooser";
 	var win = dad._windows[title];
 	if(!win){
 		var newId = dad.newSeqId();
@@ -195,7 +195,7 @@ function newCalendarChooserWindow(){
 			Action_id: Action_id,
 			btnAction_id: btnAction_id,
 			table_id: table_id
-		}
+		};
 		var win = dad.newWindow(newId, 220,20, 300, 0, _tr(title), Jaml.render('CalendarChooserWindow', data));
 		CalendarChooserSetDate(newId, 0);
 		
@@ -207,5 +207,5 @@ function newCalendarChooserWindow(){
 			}
 		}
 	}
-	dad.bringToFront(win)
+	dad.bringToFront(win);
 }

+ 17 - 1
SquiLu/samples/coroutines.nut

@@ -1,12 +1,18 @@
 function coroutine_test(a,b)
 {
+	local gca = dad_utils.gc_scope_alert(@(ud) print(ud), "<<Gone !>> : " + __LINE__);
 	::print(a+" "+b+"\n");
 	local ret = ::suspend("suspend 1");
+	gca = dad_utils.gc_scope_alert(@(ud) print(ud), "<<Gone !>> : " + __LINE__);
 	::print("the coroutine says "+ret+"\n");
 	ret = ::suspend("suspend 2");
+	gca = dad_utils.gc_scope_alert(@(ud) print(ud), "<<Gone !>> : " + __LINE__);
 	::print("the coroutine says "+ret+"\n");
 	ret = ::suspend("suspend 3");
+	gca = dad_utils.gc_scope_alert(@(ud) print(ud), "<<Gone !>> : " + __LINE__);
 	::print("the coroutine says "+ret+"\n");
+	gca = dad_utils.gc_scope_alert(@(ud) print(ud), "<<Gone !>> : " + __LINE__);
+	::print(getstacktop());
 	return "I'm done"
 }
 
@@ -14,6 +20,13 @@ local coro = ::newthread(coroutine_test);
 
 local susparam = coro.call("test","coroutine"); //starts the coroutine
 
+function doIt(str : string){
+	print(str);
+}
+
+local a = 23;
+print(a);
+
 local i = 1;
 do
 {
@@ -22,4 +35,7 @@ do
 	++i;
 }while(coro.getstatus()=="suspended")
 
-::print("return passed ["+susparam+"]\n")
+::print("getstacktop", getstacktop());
+::print("return passed ["+susparam+"]\n")
+::print("getstacktop", getstacktop());
+print(a);

+ 5 - 2
SquiLu/samples/csv2array.nut

@@ -2,13 +2,15 @@ function fromCSV (s){
   local t = [];        // table to collect fields
   local fieldstart = 0;
   local slen = s.len();
+  //local count = 0;
   do {
+    //print("Count", ++count);
     // next field is quoted? (start with `"'?)
     if (s[fieldstart] == '"') {
       local i = s.find_close_quote(fieldstart+1);
       if (i<0) throw("unmatched \"");
       local f = s.slice(fieldstart+1, i);
-//print(f);
+//print(f, f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
        local nextc = s.find(",", i);
        if(!nextc) nextc=slen-1;
@@ -18,10 +20,11 @@ function fromCSV (s){
     {
       local nexti = s.find(",", fieldstart);
       if(!nexti) nexti = slen-1;
-//print("nn", s.slice(fieldstart, nexti))
+//print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
       t.push(s.slice(fieldstart, nexti));
       fieldstart = nexti + 1;
     }
   } while(fieldstart < slen);
+  if(s[slen-1] == ',') t.push("");
   return t;
 }

+ 2 - 0
SquiLu/samples/spectralnorm.nut

@@ -8,6 +8,7 @@ local function A(i, j){
 }
 
 local function Av(x, y, N){
+  local A = A;
   for(local i=0; i < N; ++i){
     local a = 0
     for(local j=0; j < N; ++j) a += x[j] * A(i, j)
@@ -16,6 +17,7 @@ local function Av(x, y, N){
 }
 
 local function Atv(x, y, N){
+  local A = A;
   for(local i=0; i < N; ++i){
     local a = 0
     for(local j=0; j < N; ++j) a += x[j] * A(j, i)

+ 7 - 7
SquiLu/samples/test-class-destructor.nut

@@ -3,13 +3,13 @@ class MyClass {
 	
 	constructor(){
 		//base.constructor();
-		_num = 0;
-		print("constructor");
+		_num = 1;
+		print("constructor", this);
 	}
 
 	destructor(){
 		//base.destructor();
-		print("destructor");
+		print("destructor", this);
 	}
 }
 
@@ -17,18 +17,18 @@ class MyDerivedClass extends MyClass {
 	constructor(){
 		base.constructor();
 		_num = 2;
-		print("derived constructor");
+		print("derived constructor", this);
 	}
 
 	destructor(){
 		base.destructor();
-		print("derived destructor");
+		print("derived destructor", this);
 	}	
 }
 
 local a = MyClass();
 print(a._num);
-a.destructor();
+//a.destructor();
 local b = MyDerivedClass();
 print(b._num);
-b.destructor();
+//b.destructor();

+ 0 - 1
SquiLu/samples/test-class-static.nut

@@ -46,4 +46,3 @@ AClass.count = 3;
 print(a.count);
 AClass.count++;
 print(AClass.count);
-

+ 25 - 2
SquiLu/samples/test-class.nut

@@ -1,4 +1,4 @@
-class A {
+local A = class {
 	a = null;
 	b = null;
 	static c = 99;
@@ -12,5 +12,28 @@ a.a = 3;
 b.a = 5;
 b.d.push(44);
 a.d.push(55);
+a.c = 66;
+b.c = 77;
 
-print(a.a, b.a, b.c, a.d[0], b.d[1]);
+print(a.a, a.c, b.a, b.c, a.d[0], b.d[1]);
+
+local B = class {
+	static cfields = ["a", "b", "c", "d"];
+	constructor(){
+		foreach(k in cfields) this[k] = 0;
+	}
+}
+
+foreach(k in B.cfields) B[k] <- null;
+
+local cb = B();
+
+foreach(k,v in B) print(k, cb[k]);
+
+local C = class extends B {
+	cc = null;
+}
+
+local cc = C();
+cc.cc = 43;
+print(cc.cc);

+ 5 - 3
SquiLu/samples/test-replace.nut

@@ -20,14 +20,15 @@ function fromCSV (s){
   local t = [];        // table to collect fields
   local fieldstart = 0;
   local slen = s.len();
+  //local count = 0;
   do {
+    //print("Count", ++count);
     // next field is quoted? (start with `"'?)
     if (s[fieldstart] == '"') {
       local i = s.find_close_quote(fieldstart+1);
-      //local i = my_find_close_quote(s, fieldstart+1);
       if (i<0) throw("unmatched \"");
       local f = s.slice(fieldstart+1, i);
-//print(f);
+//print(f, f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
        local nextc = s.find(",", i);
        if(!nextc) nextc=slen-1;
@@ -37,11 +38,12 @@ function fromCSV (s){
     {
       local nexti = s.find(",", fieldstart);
       if(!nexti) nexti = slen-1;
-//print("nn", s.slice(fieldstart, nexti))
+//print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
       t.push(s.slice(fieldstart, nexti));
       fieldstart = nexti + 1;
     }
   } while(fieldstart < slen);
+  if(s[slen-1] == ',') t.push("");
   return t;
 }
 

+ 11 - 0
SquiLu/samples/test-slave-vm.nut

@@ -36,7 +36,18 @@ if(!globals.get("_slave_", false)){
 }
 else print("I'm a slave !");
 
+/*
 local slave_func = "say_something";
 vm.compilestring(slave_func, "::print(\"ciao\")");
 vm.call(false, slave_func);
+*/
 
+try {
+	local slave_func = "getTable";
+	vm.compilestring(slave_func, [==[return {"nodes":[{"_id":"5206163192518f6f21000180","tag":"body","classes":[],"@class":[],"children":["1d4048ee-0942-df4c-a506-5ee3e3ca8b6d"],"data":{"attr":{},"clearfix":false}},{"_id":"1d4048ee-0942-df4c-a506-5ee3e3ca8b6d","tag":"img","classes":[],"@class":[],"@src":"/wf/design/blank/comment.png","children":[],"data":{"attr":{"src":"/wf/design/blank/comment.png"},"image":{"width":100,"height":35,"size":1943,"fileName":"comment.png","_id":"dad234"}}}],"dropCount":0,"lastSynced":null}]==]);
+	local slave_tbl = vm.call(true, slave_func);
+	foreach(k,v in slave_tbl) print(k,v);
+}
+catch(e){
+	print(e);
+}

+ 7 - 4
SquiLu/samples/test-tinyxml2.nut

@@ -1,15 +1,18 @@
 local xml = TinyXml2.XMLDocument();
-
-local text = xml.NewText("name");
+local element = xml->InsertEndChild( xml->NewDeclaration() );
+local text = xml->InsertEndChild( xml.NewText("name") );
 text.Value("Domingo");
 print(text, text instanceof TinyXml2.XMLText);
-local comment = xml.NewComment("Notes");
+local comment = xml->InsertEndChild( xml.NewComment("Notes") );
 comment.Value("Hello World !");
 print(comment, type(comment));
 xml.SaveFile("test.xml");
+print(xml.tostring());
+xml.LoadFile("test.xml");
+print(xml.tostring());
 
 local doc = new TinyXml2.XMLDocument();
-local element = doc->InsertEndChild( doc->NewDeclaration() );
+element = doc->InsertEndChild( doc->NewDeclaration() );
 element = doc->InsertEndChild( doc->NewElement( "name" ) );
 element->InsertEndChild( doc->NewText( "Domingo" ) );
 element = doc->InsertEndChild( doc->NewElement( "parent" ) );

+ 9 - 0
SquiLu/samples/test-weakref.nut

@@ -7,3 +7,12 @@ local instBlob = blob();
 print(instBlob);
 weakv = instBlob.weakref();
 print(weakv);
+
+local t = {}
+local a = ["first","second","third"]
+//creates a weakref to the array and assigns it to a table slot
+t.thearray <- a.weakref();
+print(t.thearray[0]);
+a = 123;
+::print(typeof(t.thearray))
+

+ 193 - 1
SquiLu/squilu.cbp

@@ -290,7 +290,7 @@
 				<Option type="1" />
 				<Option compiler="gcc" />
 				<Compiler>
-					<Add option="-Os" />
+					<Add option="-O2" />
 					<Add option="-Wall" />
 					<Add option="-DNEED_SUBLATIN_C=1" />
 					<Add option="-DSQUILU_ALONE=1" />
@@ -436,6 +436,8 @@
 					<Add library="mpdecimal" />
 					<Add library="hpdfs" />
 					<Add library="discount" />
+					<Add library="X11" />
+					<Add library="fontconfig" />
 					<Add directory="../../zeromq-3.2.2" />
 					<Add directory="../fltk/lib" />
 					<Add directory="../flu" />
@@ -473,6 +475,108 @@
 					<Add directory="../fltk/lib" />
 				</Linker>
 			</Target>
+			<Target title="Release FLTK 64bits Lib">
+				<Option output="bin/libsquilu" prefix_auto="1" extension_auto="1" />
+				<Option working_dir="" />
+				<Option object_output="obj/Release/" />
+				<Option type="2" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-fomit-frame-pointer" />
+					<Add option="-fexpensive-optimizations" />
+					<Add option="-O3" />
+					<Add option="-Wall" />
+					<Add option="-g" />
+					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
+					<Add option="-DPROFILE_SQVM22=1" />
+					<Add option="-D_SQ64=1" />
+					<Add option="-DCONFIG_64=1" />
+					<Add option="-DHAS_UNIX_DOMAIN_SOCKETS=1" />
+					<Add option="-DUSE_SIGNAL_HANDLER=1" />
+					<Add directory="../../zeromq-3.2.2/include" />
+					<Add directory="../fltk" />
+					<Add directory="../libharu/include" />
+					<Add directory="../flu" />
+				</Compiler>
+				<Linker>
+					<Add library="../../zeromq-3.2.2/libzmq3.a" />
+					<Add library="pthread" />
+					<Add library="rt" />
+					<Add library="dl" />
+					<Add library="axtls" />
+					<Add library="fltkutils" />
+					<Add library="fltk_images" />
+					<Add library="fltk_png" />
+					<Add library="fltk_jpeg" />
+					<Add library="fltk_z" />
+					<Add library="fltk" />
+					<Add library="Xext" />
+					<Add library="Xft" />
+					<Add library="Xinerama" />
+					<Add library="mpdecimal" />
+					<Add library="hpdfs" />
+					<Add library="discount" />
+					<Add library="X11" />
+					<Add library="fontconfig" />
+					<Add directory="../../zeromq-3.2.2" />
+					<Add directory="../fltk/lib" />
+					<Add directory="../flu" />
+					<Add directory="../libharu/src" />
+				</Linker>
+			</Target>
+			<Target title="Release FLTK 64bits Computed Gotos">
+				<Option output="bin/squilu" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release/" />
+				<Option type="1" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-fomit-frame-pointer" />
+					<Add option="-fexpensive-optimizations" />
+					<Add option="-O3" />
+					<Add option="-Wall" />
+					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
+					<Add option="-DPROFILE_SQVM22=1" />
+					<Add option="-D_SQ64=1" />
+					<Add option="-DCONFIG_64=1" />
+					<Add option="-DHAS_UNIX_DOMAIN_SOCKETS=1" />
+					<Add option="-DUSE_SIGNAL_HANDLER=1" />
+					<Add option="-DUSE_COMPUTED_GOTOS=1" />
+					<Add directory="../../zeromq-3.2.2/include" />
+					<Add directory="../fltk" />
+					<Add directory="../libharu/include" />
+					<Add directory="../flu" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+					<Add library="../../zeromq-3.2.2/libzmq3.a" />
+					<Add library="pthread" />
+					<Add library="rt" />
+					<Add library="dl" />
+					<Add library="axtls" />
+					<Add library="fltkutils" />
+					<Add library="fltk_images" />
+					<Add library="fltk_png" />
+					<Add library="fltk_jpeg" />
+					<Add library="fltk_z" />
+					<Add library="fltk" />
+					<Add library="Xext" />
+					<Add library="Xft" />
+					<Add library="Xinerama" />
+					<Add library="mpdecimal" />
+					<Add library="hpdfs" />
+					<Add library="discount" />
+					<Add library="X11" />
+					<Add library="fontconfig" />
+					<Add directory="../../zeromq-3.2.2" />
+					<Add directory="../fltk/lib" />
+					<Add directory="../flu" />
+					<Add directory="../libharu/src" />
+				</Linker>
+			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wall" />
@@ -513,6 +617,7 @@
 			<Add option="-DSSL_STATIC_LIBRARY=1" />
 			<Add option="-DPDF_USING_ZLIB=1" />
 			<Add option="-DRS232_STATIC=1" />
+			<Add option="-DWITH_UUID=1" />
 			<Add directory="include" />
 			<Add directory="sqstdlib" />
 			<Add directory="../myaxtls" />
@@ -525,11 +630,13 @@
 			<Add directory="../SquiLu-ext" />
 			<Add directory="/usr/include/mysql" />
 			<Add directory="../gumbo" />
+			<Add directory="../minizip" />
 		</Compiler>
 		<Linker>
 			<Add library="m" />
 			<Add library="uuid" />
 			<Add library="gumbo" />
+			<Add library="../minizip/libminizip.a" />
 			<Add directory="lib" />
 			<Add directory="../myaxtls" />
 			<Add directory="../mpdecimal" />
@@ -564,6 +671,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/dynamic_library.h">
 			<Option target="Debug" />
@@ -578,6 +687,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/fpdf.cpp">
 			<Option target="Debug" />
@@ -592,6 +703,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/fpdf.h">
 			<Option target="Debug" />
@@ -606,6 +719,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/lua_socket.cpp">
 			<Option target="Debug" />
@@ -620,6 +735,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/lua_socket.h">
 			<Option target="Debug" />
@@ -634,6 +751,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/mongoose.c">
 			<Option compilerVar="CC" />
@@ -649,6 +768,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/mongoose.h">
 			<Option target="Debug" />
@@ -663,6 +784,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/pdf-font.cpp">
 			<Option target="Debug" />
@@ -677,6 +800,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/pdf-font.h">
 			<Option target="Debug" />
@@ -691,6 +816,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_axtls.c">
 			<Option compilerVar="CC" />
@@ -706,6 +833,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_base64.cpp">
 			<Option target="Debug" />
@@ -720,6 +849,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_decimal.cpp">
 			<Option target="Debug" />
@@ -733,6 +864,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_fastcgi.cpp">
 			<Option target="&lt;{~None~}&gt;" />
@@ -750,6 +883,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_fpdf.cpp">
 			<Option target="Debug" />
@@ -764,6 +899,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_fs.c">
 			<Option compilerVar="CC" />
@@ -779,6 +916,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_gumbo.cpp" />
 		<Unit filename="../SquiLu-ext/sq_markdown.cpp">
@@ -793,6 +932,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mix.cpp">
 			<Option target="Debug" />
@@ -807,6 +948,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mongoose.cpp">
 			<Option target="Debug" />
@@ -821,6 +964,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mysql.cpp" />
 		<Unit filename="../SquiLu-ext/sq_parsecsv.cpp">
@@ -835,6 +980,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_postgresql.cpp">
 			<Option target="Debug" />
@@ -848,6 +995,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_rs232.c">
 			<Option compilerVar="CC" />
@@ -863,6 +1012,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_slave_vm.cpp">
 			<Option target="Debug" />
@@ -877,6 +1028,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_socket.cpp">
 			<Option target="Debug" />
@@ -891,6 +1044,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_sqlite3.cpp">
 			<Option target="Debug" />
@@ -905,6 +1060,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_sys.cpp">
 			<Option target="&lt;{~None~}&gt;" />
@@ -922,6 +1079,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_zlib.cpp">
 			<Option target="Debug" />
@@ -936,6 +1095,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_zmq3.cpp">
 			<Option target="Debug" />
@@ -949,6 +1110,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqlite3.c">
 			<Option compilerVar="CC" />
@@ -964,6 +1127,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqlite3.h">
 			<Option target="Debug" />
@@ -978,6 +1143,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqmodule.h">
 			<Option target="Debug" />
@@ -992,6 +1159,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqratimport.cpp">
 			<Option target="Debug" />
@@ -1006,6 +1175,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqratimport.h">
 			<Option target="Debug" />
@@ -1020,6 +1191,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/tinyxml2.cpp">
 			<Option target="Debug" />
@@ -1034,6 +1207,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/tinyxml2.h">
 			<Option target="Debug" />
@@ -1048,6 +1223,8 @@
 			<Option target="Release 64bits" />
 			<Option target="Release FLTK 64bits" />
 			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Lib" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="dadbiz.rc">
 			<Option compilerVar="WINDRES" />
@@ -1064,6 +1241,21 @@
 		<Unit filename="include/squirrel.h" />
 		<Unit filename="sq/sq.c">
 			<Option compilerVar="CC" />
+			<Option target="Debug" />
+			<Option target="Release" />
+			<Option target="Release clang" />
+			<Option target="Release win32" />
+			<Option target="Release FLTK" />
+			<Option target="Debug FLTK" />
+			<Option target="Release FLTK win32" />
+			<Option target="Release FLTK win32 no console" />
+			<Option target="Release alone" />
+			<Option target="Release alone wince" />
+			<Option target="Release wince" />
+			<Option target="Release 64bits" />
+			<Option target="Release FLTK 64bits" />
+			<Option target="Debug 64bits" />
+			<Option target="Release FLTK 64bits Computed Gotos" />
 		</Unit>
 		<Unit filename="sqstdlib/sqstdaux.cpp" />
 		<Unit filename="sqstdlib/sqstdblob.cpp" />

Some files were not shown because too many files changed in this diff