/ Check-in [44acfc514f]
DEMO | DOWNLOAD | DEPLOY | SEARCH
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add isMain on cmdline source.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:44acfc514fe0d3cda099e28d4367ddb78932b982
User & Date: pmacdona 2019-05-11 22:17:11
Context
2019-05-13
14:15
Release "2.8.27". require: change default version back to 0, and add back lastReq field. check-in: fea7a7d0f4 user: pmacdona tags: trunk
2019-05-11
22:17
Add isMain on cmdline source. check-in: 44acfc514f user: pmacdona tags: trunk
2019-05-08
02:25
Interactive integrity check. check-in: 1540c573a7 user: pmacdona tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to md/Home.md.

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
</td>

<td>
<a href="https://jsish.org">
<img src="../www/site/logojsi_dark2.png" style="vertical-align:middle" class="spinimg"></a>
<span style="border-bottom:1px solid"> Javascript interpreter + embedded Web-server</span>
<ul>
<li>With functions supporting <a href="Types.md">typed parameters</a>.</li>
<li>WebSockets, Sqlite and other prerequisites builtin.</li>
<li>A ZVFS to extend functionality with embedded-scripts.</li>
<li>Static binaries for Linux and/or Windows.</li>
<li>Implementated in <b>C</b> and embeddable with single <b>#include</b>.</li>
</ul>

<b>New Users:</b> Click here for <a href="https://jsish.org/fossil/jsi/alerts">Alerts</a> or the <a href="https://jsish.org/fossil/jsi/draft3/doc/ckout/md/Home.md">Light-UI</a>

</td>
</tr></table>

Topics
----

- **Start**: [Download](Download.md), [Building](Download.md#Building), [Using](Download.md#Using), [Embedding](Download.md#Embedding)
- **Docs**: [Builtins](Builtins.md), [Reference](Reference.md), [FAQ](../../../wiki/FAQ), [Index](Docs.md), [License](Misc.md#License), [Language](Misc.md#Language Comparisons), [ECMA](Misc.md#ECMA Compatibilty)
- **Development**: [Types](Types.md), [Strict Mode](Types.md#Strict Mode), [Type Checking](Types.md#Checking), [Debugging](Debug.md), [Errors](Testing.md#Errors), [Logging](Logging.md)
- **Core**: [System](Builtins.md#System), [Info](Builtins.md#Info), [Interp](Interp.md), [Format](Logging.md#format), [File-System](Builtins.md#File), [Events](Builtins.md#Event)
- **Integration**: [Modules](Coding.md#Modules), [Packages](Coding.md#Packages), [Auto-Load](Coding.md#Auto-Load)
- **Web**: [Pre-processors](Builtins.md#WebSocket), [Markup](Reference.md#Util), [JSON](Builtins.md#JSON)
- **Miscellaneous**: [CData](CData.md), [Threads](Interp.md#Thread-Interps), [Signal](Builtins.md#Signal), [Sqlite](Sqlite.md), [MySQL](MySql.md), [Zvfs](Builtins.md#Zvfs), [Socket](Builtins.md#Socket), [WebSocket](Builtins.md#WebSocket)
- **Tools**: [Testing](Testing.md), [Tracing](Coding.md#Execution Trace), [Profiling](Coding.md#Code Profile), [Code-Coverage](Coding.md#Code Coverage)
- **C/C++**: [Jsi-Lite](C-API.md#Jsi-Lite), [C Extension](CData.md), [DString](C-API.md#DString), [CData](CData.md), [Options](C-API.md#Options), [Sqlite-C](DBQuery.md), [JSON-C](C-API.md#JSON)
- **Applications**: [Ledger](Ledger.md), [SqliteUI](Download.md#Apps), [Web Server](Coding.md#Server)

What is it?
----

Jsi seeks to fill the void in current development environments by providing:

- a feature-dense development environment,
- based on the most widely available and used languages (Javascript and C),
- with builtin Database (Sqlite) and GUI capabilities (WebSocket),
- is easily extended and embedded in C,
- all while eschewing dependencies and excess complexity.


What is Jsi **NOT**?:

- the latest and greatest ECMA features.
- Object oriented and other kitchen-sink abstractions.
- Duplication, or multiple way to achieve the same goal.

Packaging
---------
<table class="mytbl"><tr>

<td>
A <a href="Deploy.md">Deploy</a> is a zip/sqlar archive or fossil







|
|
|
|
<







|













|


|

|
<
|
<
<
>

<
<
<
<
<







63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101


102
103





104
105
106
107
108
109
110
</td>

<td>
<a href="https://jsish.org">
<img src="../www/site/logojsi_dark2.png" style="vertical-align:middle" class="spinimg"></a>
<span style="border-bottom:1px solid"> Javascript interpreter + embedded Web-server</span>
<ul>
<li><a href="Types.md">Typed function-parameters</a>.</li>
<li><a href="Builtins.md#Zvfs">Zvfs integrated scripts</a> for extended functionality.</li>
<li><a href="Download.md#Embedding">Embed in <b>C</b> programs</a> using only <b>#include</b>.</li>
<li>WebSockets, Sqlite and other common prerequisites built-in.</li>

</ul>

<b>New Users:</b> Click here for <a href="https://jsish.org/fossil/jsi/alerts">Alerts</a> or the <a href="https://jsish.org/fossil/jsi/draft3/doc/ckout/md/Home.md">Light-UI</a>

</td>
</tr></table>

Index
----

- **Start**: [Download](Download.md), [Building](Download.md#Building), [Using](Download.md#Using), [Embedding](Download.md#Embedding)
- **Docs**: [Builtins](Builtins.md), [Reference](Reference.md), [FAQ](../../../wiki/FAQ), [Index](Docs.md), [License](Misc.md#License), [Language](Misc.md#Language Comparisons), [ECMA](Misc.md#ECMA Compatibilty)
- **Development**: [Types](Types.md), [Strict Mode](Types.md#Strict Mode), [Type Checking](Types.md#Checking), [Debugging](Debug.md), [Errors](Testing.md#Errors), [Logging](Logging.md)
- **Core**: [System](Builtins.md#System), [Info](Builtins.md#Info), [Interp](Interp.md), [Format](Logging.md#format), [File-System](Builtins.md#File), [Events](Builtins.md#Event)
- **Integration**: [Modules](Coding.md#Modules), [Packages](Coding.md#Packages), [Auto-Load](Coding.md#Auto-Load)
- **Web**: [Pre-processors](Builtins.md#WebSocket), [Markup](Reference.md#Util), [JSON](Builtins.md#JSON)
- **Miscellaneous**: [CData](CData.md), [Threads](Interp.md#Thread-Interps), [Signal](Builtins.md#Signal), [Sqlite](Sqlite.md), [MySQL](MySql.md), [Zvfs](Builtins.md#Zvfs), [Socket](Builtins.md#Socket), [WebSocket](Builtins.md#WebSocket)
- **Tools**: [Testing](Testing.md), [Tracing](Coding.md#Execution Trace), [Profiling](Coding.md#Code Profile), [Code-Coverage](Coding.md#Code Coverage)
- **C/C++**: [Jsi-Lite](C-API.md#Jsi-Lite), [C Extension](CData.md), [DString](C-API.md#DString), [CData](CData.md), [Options](C-API.md#Options), [Sqlite-C](DBQuery.md), [JSON-C](C-API.md#JSON)
- **Applications**: [Ledger](Ledger.md), [SqliteUI](Download.md#Apps), [Web Server](Coding.md#Server)

Purpose
----

Jsi seeks to fill the void in current development environments:

- Provide a feature-dense scripting environment based on Javascript.

- Has Database (Sqlite) and GUI capabilities (WebSocket) builtin.


- Is easily embedded in C and extended.







Packaging
---------
<table class="mytbl"><tr>

<td>
A <a href="Deploy.md">Deploy</a> is a zip/sqlar archive or fossil

Changes to src/jsi.c.

20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
.....
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
.....
23904
23905
23906
23907
23908
23909
23910

23911
23912
23913
23914
23915
23916
23917
.....
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
.....
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
            Jsi_DSFree(&dStr);

        } else {
            if (argc>1) {
                jsi_vf = Jsi_ValueNewStringKey(interp, argv[first]);
                Jsi_IncrRefCount(interp, jsi_vf);
            }
            rc = Jsi_EvalFile(interp, jsi_vf, JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX);
            if (jsi_vf) {
                Jsi_DecrRefCount(interp, jsi_vf);
                jsi_vf = NULL;
            }

        }
    }
................................................................................
    if (!interp->iskips)
        puts("Jsish interactive: see 'help [cmd]' or 'history'.  \\ cancels > input."
#if JSI__SIGNAL
        "  ctrl-c aborts running script."
#endif
        );
    while (done==0 && interp->exited==0) {
        buf = get_inputline(interp, istty, prompt);
        if (buf) {
            if (buf[0] == '\\' && !buf[1]) {
                 Jsi_DSSetLength(&dStr, 0);
                 prompt = interp->subOpts.prompt;
                 fprintf(stderr, "abandoned input");
            } else
                Jsi_DSAppend(&dStr, buf, NULL);
................................................................................
                    rc = Jsi_EvalString(interp, tbuf, JSI_RETURN);
                }
            }
            if (!wantHelp) {
                if (!Jsi_Strncmp(buf,"var ", 4) && Jsi_Strchr(buf, '\n')==NULL && Jsi_Strchr(buf, ';')==NULL)
                    Jsi_Strcpy(buf+Jsi_Strlen(buf), ";"); // Added space above so strcat ok.
                rc = Jsi_EvalString(interp, buf, JSI_EVAL_RETURN);

#ifdef JSI_HAS_READLINE
                if (rc == JSI_OK)
                    Jsi_DSAppend(&sHist, buf, "\n", NULL);
#endif
            }
        }
        else
................................................................................
    const char *anam;
    bool isMain = jsi_isMain(interp);
    if (interp->isMain)
        interp->isMain = 0;
    
    if (v2 && !Jsi_ValueIsObjType(interp, v2, JSI_OT_ARRAY))
        return Jsi_LogError("arg 2: expected array|undefined");
    if (!v1) {
        mod = interp->framePtr->fileName;
        if (mod) mod = Jsi_Strrchr(mod, '/');
        if (!mod) return JSI_ERROR;
        mod++;
        cp = Jsi_Strrchr(mod, '.');
        int len = (cp?(cp-mod):(int)Jsi_Strlen(mod));
        mod = Jsi_DSAppendLen(&dStr, mod, len);
................................................................................
    { "parseFloat", parseFloatCmd,   1,  1, "val", .help="Convert string to a double", .retType=(uint)JSI_TT_NUMBER },
    { "parseOpts",  SysParseOptsCmd, 2,  3, "self:object|userobj, options:object, conf:object|null|undefined", .help="Parse options", .retType=(uint)JSI_TT_ANY, .flags=0},
    { "printf",     SysPrintfCmd,    1, -1, "format:string, ...", .help="Formatted output to stdout", .retType=(uint)JSI_TT_VOID, .flags=0 },
    { "provide",    SysProvideCmd,   0,  3, "name:string|function=void, version:number|string=1.0, opts:object|function=void", .help="Provide a package for use with require. Default is the file tail-rootname", .retType=(uint)JSI_TT_VOID },
    { "puts",       SysPutsCmd,      1, -1, "val, ...", .help="Output one or more values to stdout", .retType=(uint)JSI_TT_VOID, .flags=0, .info=FN_puts },
    { "quote",      SysQuoteCmd,     1,  1, "val:string", .help="Return quoted string", .retType=(uint)JSI_TT_STRING },
    { "require",    SysRequireCmd,   0,  3, "name:string=void, version:number|string=1, options:object=void", .help="Load/query packages", .retType=(uint)JSI_TT_NUMBER|JSI_TT_OBJECT|JSI_TT_ARRAY, .flags=0, .info=FN_require, .opts=jsiModuleOptions },
    { "runModule",  SysRunModuleCmd, 0,  2, "cmd:string|function=void, conf:array=undefined", .help="Invoke named module. If name is empty, uses file basename. If isMain and no args givine parses console.args", .retType=(uint)JSI_TT_ANY, .flags=0},
    { "sleep",      SysSleepCmd,     0,  1, "secs:number=1.0",  .help="sleep for N milliseconds, minimum .001", .retType=(uint)JSI_TT_VOID },
#ifndef JSI_OMIT_EVENT
    { "setInterval",setIntervalCmd,  2,  2, "callback:function, ms:number", .help="Setup recurring function to run every given millisecs", .retType=(uint)JSI_TT_NUMBER },
    { "setTimeout", setTimeoutCmd,   2,  2, "callback:function, ms:number", .help="Setup function to run after given millisecs", .retType=(uint)JSI_TT_NUMBER },
#endif
    { "source",     SysSourceCmd,    1,  2, "val:string|array, options:object=void",  .help="Load and evaluate source files", .retType=(uint)JSI_TT_VOID, .flags=0, .info=0, .opts=SourceOptions},
    { "strftime",   DateStrftimeCmd, 0,  2, "num:number=null, options:string|object=void",  .help="Format numeric time (in ms) to a string", .retType=(uint)JSI_TT_STRING, .flags=0, .info=FN_strftime, .opts=DateOptions },







|







 







|







 







>







 







|







 







|







20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
.....
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
.....
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
.....
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
.....
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
            Jsi_DSFree(&dStr);

        } else {
            if (argc>1) {
                jsi_vf = Jsi_ValueNewStringKey(interp, argv[first]);
                Jsi_IncrRefCount(interp, jsi_vf);
            }
            rc = Jsi_EvalFile(interp, jsi_vf, JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX|JSI_EVAL_ISMAIN);
            if (jsi_vf) {
                Jsi_DecrRefCount(interp, jsi_vf);
                jsi_vf = NULL;
            }

        }
    }
................................................................................
    if (!interp->iskips)
        puts("Jsish interactive: see 'help [cmd]' or 'history'.  \\ cancels > input."
#if JSI__SIGNAL
        "  ctrl-c aborts running script."
#endif
        );
    while (done==0 && interp->exited==0) {
        buf = get_inputline(interp, istty, (prompt?prompt:"$ "));
        if (buf) {
            if (buf[0] == '\\' && !buf[1]) {
                 Jsi_DSSetLength(&dStr, 0);
                 prompt = interp->subOpts.prompt;
                 fprintf(stderr, "abandoned input");
            } else
                Jsi_DSAppend(&dStr, buf, NULL);
................................................................................
                    rc = Jsi_EvalString(interp, tbuf, JSI_RETURN);
                }
            }
            if (!wantHelp) {
                if (!Jsi_Strncmp(buf,"var ", 4) && Jsi_Strchr(buf, '\n')==NULL && Jsi_Strchr(buf, ';')==NULL)
                    Jsi_Strcpy(buf+Jsi_Strlen(buf), ";"); // Added space above so strcat ok.
                rc = Jsi_EvalString(interp, buf, JSI_EVAL_RETURN);
                prompt = interp->subOpts.prompt;
#ifdef JSI_HAS_READLINE
                if (rc == JSI_OK)
                    Jsi_DSAppend(&sHist, buf, "\n", NULL);
#endif
            }
        }
        else
................................................................................
    const char *anam;
    bool isMain = jsi_isMain(interp);
    if (interp->isMain)
        interp->isMain = 0;
    
    if (v2 && !Jsi_ValueIsObjType(interp, v2, JSI_OT_ARRAY))
        return Jsi_LogError("arg 2: expected array|undefined");
    if (!v1 || Jsi_ValueIsNull(interp, v1)) {
        mod = interp->framePtr->fileName;
        if (mod) mod = Jsi_Strrchr(mod, '/');
        if (!mod) return JSI_ERROR;
        mod++;
        cp = Jsi_Strrchr(mod, '.');
        int len = (cp?(cp-mod):(int)Jsi_Strlen(mod));
        mod = Jsi_DSAppendLen(&dStr, mod, len);
................................................................................
    { "parseFloat", parseFloatCmd,   1,  1, "val", .help="Convert string to a double", .retType=(uint)JSI_TT_NUMBER },
    { "parseOpts",  SysParseOptsCmd, 2,  3, "self:object|userobj, options:object, conf:object|null|undefined", .help="Parse options", .retType=(uint)JSI_TT_ANY, .flags=0},
    { "printf",     SysPrintfCmd,    1, -1, "format:string, ...", .help="Formatted output to stdout", .retType=(uint)JSI_TT_VOID, .flags=0 },
    { "provide",    SysProvideCmd,   0,  3, "name:string|function=void, version:number|string=1.0, opts:object|function=void", .help="Provide a package for use with require. Default is the file tail-rootname", .retType=(uint)JSI_TT_VOID },
    { "puts",       SysPutsCmd,      1, -1, "val, ...", .help="Output one or more values to stdout", .retType=(uint)JSI_TT_VOID, .flags=0, .info=FN_puts },
    { "quote",      SysQuoteCmd,     1,  1, "val:string", .help="Return quoted string", .retType=(uint)JSI_TT_STRING },
    { "require",    SysRequireCmd,   0,  3, "name:string=void, version:number|string=1, options:object=void", .help="Load/query packages", .retType=(uint)JSI_TT_NUMBER|JSI_TT_OBJECT|JSI_TT_ARRAY, .flags=0, .info=FN_require, .opts=jsiModuleOptions },
    { "runModule",  SysRunModuleCmd, 0,  2, "cmd:string|null|function=void, conf:array=undefined", .help="Invoke named module. If name is empty, uses file basename. If isMain and no args givine parses console.args", .retType=(uint)JSI_TT_ANY, .flags=0},
    { "sleep",      SysSleepCmd,     0,  1, "secs:number=1.0",  .help="sleep for N milliseconds, minimum .001", .retType=(uint)JSI_TT_VOID },
#ifndef JSI_OMIT_EVENT
    { "setInterval",setIntervalCmd,  2,  2, "callback:function, ms:number", .help="Setup recurring function to run every given millisecs", .retType=(uint)JSI_TT_NUMBER },
    { "setTimeout", setTimeoutCmd,   2,  2, "callback:function, ms:number", .help="Setup function to run after given millisecs", .retType=(uint)JSI_TT_NUMBER },
#endif
    { "source",     SysSourceCmd,    1,  2, "val:string|array, options:object=void",  .help="Load and evaluate source files", .retType=(uint)JSI_TT_VOID, .flags=0, .info=0, .opts=SourceOptions},
    { "strftime",   DateStrftimeCmd, 0,  2, "num:number=null, options:string|object=void",  .help="Format numeric time (in ms) to a string", .retType=(uint)JSI_TT_STRING, .flags=0, .info=FN_strftime, .opts=DateOptions },

Changes to src/jsiInterp.c.

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
            Jsi_DSFree(&dStr);

        } else {
            if (argc>1) {
                jsi_vf = Jsi_ValueNewStringKey(interp, argv[first]);
                Jsi_IncrRefCount(interp, jsi_vf);
            }
            rc = Jsi_EvalFile(interp, jsi_vf, JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX);
            if (jsi_vf) {
                Jsi_DecrRefCount(interp, jsi_vf);
                jsi_vf = NULL;
            }

        }
    }







|







863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
            Jsi_DSFree(&dStr);

        } else {
            if (argc>1) {
                jsi_vf = Jsi_ValueNewStringKey(interp, argv[first]);
                Jsi_IncrRefCount(interp, jsi_vf);
            }
            rc = Jsi_EvalFile(interp, jsi_vf, JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX|JSI_EVAL_ISMAIN);
            if (jsi_vf) {
                Jsi_DecrRefCount(interp, jsi_vf);
                jsi_vf = NULL;
            }

        }
    }