Hello world/Graphical: Difference between revisions

Content added Content deleted
(Add Jsish, with libAgar GUI and CData module bindings)
Line 1,458: Line 1,458:
{{out}}
{{out}}
jq -n -r -f Hello_word_Graphical.jq > Hello_word_Graphical.svg
jq -n -r -f Hello_word_Graphical.jq > Hello_word_Graphical.svg

=={{header|Jsish}}==
Using JSI CData processing, C, and linking to libAgar.
{{out}}
<pre>prompt$ jsish
Jsish interactive: see 'help [cmd]'. \ cancels > input. ctrl-c aborts running script.
# require('JsiAgarGUI')
1
# JsiAgarGUI.alert("Goodbye, World!");
#</pre>
Window pops up with message and Ok button.

That is based on JSI CData, a blend of typed Javascript and C, interwoven via a preprocessor.

<lang c>extension JsiAgarGUI = { // libAgar GUI from Jsi
/*
Alert popup, via libAgar and Jsish CData
tectonics:
jsish -c JsiAgar.jsc
gcc `jsish -c -cflags true JsiAgar.so` `agar-config --cflags --libs`
jsish -e 'require("JsiAgar"); JsiAgar.alert("Goodbye, World!");'
*/
#include <agar/core.h>
#include <agar/gui.h>

/* Terminate on close */
void windDown(AG_Event *event) {
AG_Terminate(0);
}

function alert(msg:string):void { // Display a JsiAgar windowed message
/* Native C code block (in a JSI function wrapper) */
AG_Window *win;
AG_Box *box;
AG_Label *lab;

Jsi_RC rc = JSI_OK;

if (AG_InitCore(NULL, 0) == -1 || AG_InitGraphics(0) == -1) return (JSI_ERROR);
AG_BindStdGlobalKeys();

win = AG_WindowNew(0);

box = AG_BoxNew(win, AG_BOX_VERT, 0);
AG_LabelNewS(box, AG_LABEL_HFILL, msg);

AG_ButtonNewFn(box, AG_BUTTON_HFILL, "Ok", AGWINDETACH(win), "%p", win);

AG_SetEvent(win, "window-detached", windDown, NULL);
AG_WindowShow(win);

AG_EventLoop();

AG_DestroyGraphics();
AG_Destroy();

return rc;
}
};</lang>

Build rules are ''jsish -c'' preprocessor, query ''jsish'' for C compile time flags, compile the C, load the module into jsish via ''require''.

<pre>prompt$ make -B -f Makefile.jsc hello
jsish -c JsiAgarGUI.jsc
gcc `jsish -c -cflags true JsiAgarGUI.so` `agar-config --cflags --libs`
jsish -e 'require("JsiAgarGUI"); JsiAgarGUI.alert(" Goodbye, World! ");'</pre>

And a window pops up with the message and an Ok button.

First command ''jsish -c'' runs a JSI to C preprocessor, generating a ''.h'' C source file.

For the second step, gcc is called with the output of a ''jsish -c -cflags true'' query, libagar runtime is linked in with more substitution for Agar compiler commands. The query output will be something like (this is site local, details will change per machine setup):

<pre>prompt$ jsish -c -cflags true JsiAgarGUI.so
-g -Og -O0 -Wall -fPIC -DJSI__SQLITE=1 -DJSI__READLINE=1 -fno-diagnostics-show-caret -Wc++-compat
-Wwrite-strings -DCDATA_MAIN=1 -x c -rdynamic -I/home/btiffin/forge/jsi/jsish/src -DJSI__WEBSOCKET=1
-I/home/btiffin/forge/jsi/jsish/websocket/src/lib -I/home/btiffin/forge/jsi/jsish/websocket/src/build
-I/home/btiffin/forge/jsi/jsish/websocket/unix -I/home/btiffin/forge/jsi/jsish/websocket/build/unix
-o JsiAgarGUI.so JsiAgarGUI.h -lm -shared -DCDATA_SHARED=1 -L /home/btiffin/forge/jsi/jsish/websocket/build/unix/
-lwebsockets -I/home/btiffin/forge/jsi/jsish/sqlite/src -L /home/btiffin/forge/jsi/jsish/sqlite/build/unix/
-lsqlite3 -lm -ldl -lpthread

prompt$ agar-config --cflags --libs
-I/usr/local/include/agar -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/freetype2
-I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libpng16
-L/usr/local/lib -lag_gui -lag_core -lSDL -lpthread -lfreetype -lfontconfig -lfreetype
-L/usr/local/lib -lGL -lX11 -lXinerama -lm -L/usr/lib -ljpeg -L/usr/lib64 -lpng16 -ldl</pre>

A JSI ready module is created, the C build rules managed by CData along with the ''.jsc'' JSI to C to JSI code generation.

As listed at the top, this GUI can be called up while in the interactive console.


=={{header|Just Basic}}==
=={{header|Just Basic}}==