Programming Environment for Numerical Computing

Version 1.4 Build 1701

Start Guide

The main goal of Comet is to provide an easy-to-use development environment for numerical computing using the Lua programming language on Android, Linux and Windows. It integrates the Lua scripting engine with all Lua functionalities, and a lot of specific Comet functionalities including numerical functions (linear algebra, differential equations, mathematical optimization, etc.), data plotting and analysis modules and extended mathematical library.

Within the Comet environment, you can develop algorithms for science and engineering with one of the most elegant and fast scripting languages.

To learn the Lua programming language, you can visit the Lua official website: http://www.lua.org Excellent tutorials, covering all Lua aspect from basics to advanced programming techniques, can be found here: http://lua-users.org/wiki/TutorialDirectory

Comet can also be used as a general purpose full-featured editor supporting C/C++, Bash/Text, Python, Octave, Fortran, LaTeX and Makefile with configurable tools (e.g. to run a compiler or a bash script).

Comet

1. Install

For setup version (on Windows): Download comet_setup_windows.msi, double-click on the setup file and it will install Comet.

Softpedia CNET

For portable version on Windows and Linux: Download:
comet_portable_windows.zip (Windows)
or comet_portable_linux_32bit.tgz (Linux 32bit)
or comet_portable_linux_64bit.tgz (Linux 64bit)
unzip/untar in any location (USB key for example) and run comet.exe or comet in the bin directory.

For Android: Install from Google Play.

MD5 hash.

2. Introduction

The main goal of Comet is to provide an easy-to-use development environment for Lua on Android, Linux and Windows, suitable for numerical computing and data analysis. It integrates the Lua scripting engine with all Lua functionalities, and a lot of specific Comet functionalities including numerical functions (linear algebra, differential equations, nonlinear equations, etc.), data plotting and analysis modules and extended mathematical library. With Comet, you can develop algorithms for science and engineering with one of the most elegant and fast scripting languages.

To learn the Lua programming language, you can visit the Lua official website:
http://www.lua.org
Excellent tutorials, covering all Lua aspect from basics to advanced programming techniques, can be found here:
http://lua-users.org/wiki/TutorialDirectory

3. Quick Start Guide

With the toolbar, you can open, save, run/debug script, perform the standard editing actions (copy/cut/paste/undo/redo) or navigate in the document with bookmarks. You can perform the same actions, and more, with the menu. Comet includes code samples and snippets (Menu/Samples and Menu/Code menu). With code snippets, you can easily insert some pieces of code (for, switch, if, function, ...) in your script for better productivity.

For Android: If you want to change the font size, select menu/Settings. You can create a new script or save the current script to another location, by selecting menu. If you want to automatically run a script on startup (AutoRun), select menu/Settings/AutoRun and choose your script in the file explorer. If you long click the AutoRun button in menu/Settings, the AutoRun feature will be disabled. You can enable or disable the soft keyboard by selecting menu/Keyboard.

You can print text on the output area by using the Lua standard print or io.write function. To clear the output area, use the cls() function or select Clear in the context menu.

For Android: You can set the output area height by selecting S (small), M (median) or L (large) in Menu / Settings (Output).
As for Windows and Linux, Comet for Android has two graphical themes: light and dark, and syntax highlighting functionality. You can switch between themes, enable or disable syntax highlighting in menu/Settings.

You can create a new script or save the current script to another location, by selecting File/New (Menu/New on Android) or File/Save As (Menu/Save As on Android) menu or the toolbar corresponding buttons.

You can print text on the output area by using the Lua standard print function (or the io.write function). To clear the output area, use the cls() function.

You can set bookmark in you code and navigate easily by clicking click Add/Remove Bookmark, Next or Previous Bookmark (either Menu/Search or the correspond toolbar buttons). Bookmarks are saved with your document and are be restored next time you open it. The list of all active bookmarks can be displayed by selecting View/Bookmarks in the menu. The bookmarks, modification and search markers can be saved alongside the document by checking the corresponding option: 'Options/Save Navigation Info' menu.

The editor options (Font, Syntax highlighting, AutoCompletion, Call Tips, Colors, Indentation and long lines indicator, Folding …) can be easily modified in the Options menu.

You can view end of lines, white spaces, file explorer, output window, script console, tool bar, status bar … in the View menu.

You can view end of lines, white spaces, long lines vertical indicator (long lines limit to set in Options/Indentation menu), file explorer, output window, script console, toolbar, statusbar… in the View menu.

The editor toolbar includes, in addition to the commonly used commands, an integrated edit zone to (i) navigate through the current document functions (or sections for LaTeX): just drop down the list and select a function; (ii) to search in the document: just type a text and click the toolbar button to the right (or press ENTER); (iii) go to a line: just type the line number and click the toolbar button to the right (or press ENTER). Note that the document functions list can be manually updated by clicking the 'Update List' toolbar button (this list is created when the document is loaded or executed).

Comet's execution mode is designed to perform long calculations, without user interaction. This feature makes it suitable for math and algorithms development.

For Android: you can activate the long calculations mode, which set the device processor to stay awake during script execution, by selecting Menu/Settings.

Comet can be executed from the command line:
$ comet -run input [-out outfile] [-show]
input may be a filename or a double-quoted expression and the outfile is the output filename:
$ comet -run "print(sin(math.pi/4))"
$ comet -run cometin.lua -out cometout.txt
Note that the plot functions and other GUI functions are only available in the Comet GUI.

Comet integrates a Lua script console (Menu View / Script Console). You can use it as an interactive programming console to perform quick tests for example. To use the script console, simply write a Lua valid statements (example: x = math.pi/3; y = sin(x); print(y); ), and press ENTER. You can enter multi-line statements: just press SHIFT+ENTER after each line and ENTER to run. You can use any standard Lua function or Comet module.

Example:

Copy the following script in the editor...

-- Lua first script
cls()
a = math.cos(math.pi/4)
print("a = ", a)

... and click Run (or press F12 on Windows and Linux)

Comet's execution mode is designed to perform long calculations, without user interaction. This feature makes it suitable for math and algorithms development. For Android: you can activate the long calculations mode, which set the device processor to stay awake during script execution, by selecting Menu/Settings.
Comet is also available as command line executable: cometc.exe (Windows) or cometc (Linux).

4. Comet as a general purpose editor

Comet can be used as a general purpose full-featured editor supporting C/C++, Bash/Text, Python, Octave, Fortran, LaTeX and Makefile with configurable tool (e.g. to run a compiler or a bash script). The document language is automatically selected using the file extension. For unknown extension, you can manually select the document language in File/Current File/File Type menu. To configure the tools used, for example, to compile and execute code, select Options/External Tools menu. Comet supports configurable tools for C/C++, Python, LaTeX and Makefile.

To configure a specific tool, select menu Options/External Tools:

(i) For Windows, you can create a batch file (named build.bat for example), put the command in this file (example: pdflatex mydoc.tex) and add the batch command build.bat in the External Tools dialog after selecting the corresponding file type (example: LaTeX).
Example (create file build.bat and set the external tool command as build.bat) building LaTeX document under Windows (using MiKTeX):

@echo off
@set opts= -halt-on-error -file-line-error
del /f /q mydoc.pdf
pdflatex %opts% mydoc.tex
bibtex %opts% mydoc.aux
pdflatex %opts% mydoc.tex
mydoc.pdf


(ii) For Linux, similarly you can create a bash file (named build.sh for example), put the command in this file (example: pdflatex mydoc.tex) and add ./build.sh in the External Tools dialog after selecting the corresponding file type (example: LaTeX).

(iii) For Python (for both Windows or Linux), just put a command like this (replace with your installed Python interpreter): C:\Python\python.exe -u %s.py (Windows) or python -u %s.py (Linux).


Comet includes a user-defined syntax highlighting template that can be customized for a specific language or file type: click Options/User-defined Syntax menu, enter the corresponding file extension (without dot) and the space-separated list of keywords to highlight. You can save the user-defined syntax highlighting template to a file (button Save…) or load the template from a file (button Load…).

5. GUI Functions

To interact with the user, one can use the graphical user interface functions:

gui.alert(msg)

-- show an alert dialog box

answer = gui.ask(msg)

-- display Yes-No dialog. Returns 1 if Yes selected, 0 otherwise.

Example:

Copy the following script in the editor...

-- GUI
answer = gui.ask("Save calculation results?")
if answer == 1 then
    -- …
    gui.alert("Calculation results saved.")
end

... and click Run (or press F12 on Windows and Linux)

6. C Modules (for Windows and Linux)

You can extend Comet by writing you own specialized C modules. Comet integrates the main Lua headers to include in your source and you can link your shared library against the Lua Core library (luacore.dll under Windows and libluacore.so under Linux).

HowTo write and use C module:

Step 1. Write your C module and register the interface functions as in the following example:

/* file: cmodule.c */

/* put the Comet include dir in your include path */
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#ifdef WIN32
#define CMODULE_API      __declspec(dllexport)
#else
#define CMODULE_API
#endif

/* compatibility with Lua 5.1 */
#if (LUA_VERSION_NUM == 501)
#define luaL_newlib(L,f)      luaL_register(L,"cmodule",f)
#endif

/* Your function */
static int cmodule_version(lua_State* pLua)
{
     lua_pushstring(pLua, "MyModule v0.1");
     return 1;
}

static const luaL_Reg cmodule[] =
{
     { "version", cmodule_version },
     { NULL, NULL }
};

CMODULE_API int luaopen_cmodule(lua_State* pLua)
{
     luaL_newlib(pLua, cmodule);
     return 1;
}

Step 2. Build your C module with your favorite C compiler:

Use Visual C++ on Windows or gcc or Clang on Linux, for example. Before compiling, add the Comet include directory (Comet Dir/include) in the compiler include path and set the linker to link against the Comet Lua Core library (luacore.dll under Windows and libluacore.so under Linux). Under Windows and for Visual C++, you can link against luacore.lib file (under Comet Dir/lib and compiled for Visual C++ 2013) or you can generate, for your specific VC version, the lib from luacore.dll and luacore.def by using the lib tool included with Visual C++:
lib /def:"C:\Comet\luacore.def" /out:"C:\Comet\lib\luacore.lib" /machine:x86

Of course, if your module is already built or purchased you can use it as usual with the Lua ad hoc functions.

Step 3. When your module was built as dll (under Windows) or so (under Linux), you can load it and use it under Comet by using the standard Lua functions:

-- Load C module, the Lua standard way
local cmodule = require("cmodule")
print(cmodule.version())

 

In addition of the built-in modules, Comet includes five useful C modules:

(i) lvisa module to control instruments through GPIB, USB, Serial, Ethernet ... This module is available only under Windows (it can be found under the examples directory). It requires the NI VISA drivers to be installed (these drivers can be freely downloaded from the NI site: http://www.ni.com/downloads/drivers/). The NI-VISA drivers are not available for Debian and Debian-based distributions.

Using lvisa is straightforward: load module with require , initialize, open visa connection, communicate and finally close connection. All functions are included in the visa namespace.

Example:

cls()
local lvisa = require("lvisa")        -- load visa module
f = lvisa.find("GPIB?*INSTR")        -- find GPIB devices
print(lvisa.status())        -- print status
dev = f[1]        -- the first GPIB device
print(dev, "\n")        -- print device description
v = lvisa.open(dev)        -- open visa connection
print(lvisa.status())        -- print status
lvisa.write(v, "*CLS;*IDN?\n")        -- send command to device
print(lvisa.status())        -- print status
time.sleep(50)        -- sleep during 50 ms
r = lvisa.read(v,100)        -- read device IDN
print(lvisa.status())        -- print status
print(r)        -- print it
lvisa.close(v)        -- close visa connection
print(lvisa.status())        -- print status

(ii) lrs232 module to control instruments through RS232 serial port.... This module is available only under Windows. The following example shows how to use the lrs232 module:

cls()

-- add the lrs232.dll directory to package.cpath
-- (alternatively, you can put lrs232.dll in the Comet bin directory)
package.cpath = package.cpath .. ";D:\\DevC\\CModules\\?.dll"

-- load the RS232 C module
local lrs232 = require("lrs232")

-- print out info about the RS232 C module release
print(lrs232.version())

-- open the serial port and configure it
-- port_handle = lrs232.open(port_num, settings, verbose)
-- port_num: usually 1 (COM1) or 2 (COM2)
-- settings has the same meaning than in the Windows BuildCommDCB
-- function except that BuildCommDCB has no 'timeout' parameter
-- that is specific to this Comet module
-- verbose (optional): true to show detailed messages
-- returns the port handle
p = lrs232.open(1, "baud=4800 parity=n data=8 stop=2 timeout=1000", true)

-- write to the serial port
-- lrs232.write(port_handle, command)
-- port_handle: the port handle, as returned by lrs232.open
-- command to send to the device
-- returns the number of bytes written
lrs232.write(p, "*IDN?\n")

-- read from the serial port
-- r,n = lrs232.read(port_handle, bytes)
-- port_handle: the port handle, as returned by lrs232.open
-- bytes: number of bytes to read
-- returns the string read and the number of bytes read
r,n = lrs232.read(p, 128)

io.write("\n recv = ", r, " ; bytes read = ", n)
-- close the serial port
-- lrs232.close(port_handle)
-- port_handle: the port handle, as returned by lrs232.open
lrs232.close(p)

(iii) lpeg pattern matching module: documentation: http://www.inf.puc-rio.br/~roberto/lpeg/

-- http://www.inf.puc-rio.br/~roberto/lpeg/
local lpeg = require("lpeg")

-- matches a word followed by end-of-string
p = lpeg.R"az"^1 * -1

print(p:match("hello")) --> 6
print(lpeg.match(p, "hello")) --> 6
print(p:match("1 hello")) --> nil

(iv) lcrypt AES encryption module:

lcrypt = require("lcrypt")

function printbytes(t)
   local str = '{ 0x'
   for _,v in pairs(t) do
       str = str .. string.format('%02X', v)
    end
    str = str .. ' }'
    print(str, "\n")
end

cls()

-- array of bytes
inp = { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A }
print("Input:\n")
printbytes(inp)

-- AES key (16 bytes = 128 bits)
key = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
print("Key:\n")
printbytes(key)

-- encrypt the array of bytes
outp = lcrypt.encrypt(inp, key)

-- decrypt the array of bytes to compare to the input table
inp_decrypted = lcrypt.decrypt(outp, key)
print("Decrypted:\n")
printbytes(inp_decrypted)

(v) lmapm library for Arbitrary Precision Math (MAPM) by Michael C. Ring, modified Lua interface from lmapm by Luiz Henrique de Figueiredo:

cls()

-- Library for Arbitrary Precision Math (MAPM) by Michael C. Ring
-- Lua interface by Luiz Henrique de Figueiredo

lmapm = require ("lmapm")

-- lmapm library functions:
-- __add(x,y)       cbrt(x)       mod(x,y)
-- __div(x,y)       ceil(x)       mul(x,y)
-- __eq(x,y)       compare(x,y)       neg(x)
-- __lt(x,y)       cos(x)       number(x)
-- __mod(x,y)       cosh(x)       pow(x,y)
-- __mul(x,y)       digits([n])       round(x)
-- __pow(x,y)       digitsin(x)       sign(x)
-- __sub(x,y)       div(x,y)       sin(x)
-- __tostring(x)       exp(x)       sincos(x)
-- __unm(x)       exponent(x)       sinh(x)
-- abs(x)       factorial(x)       sqrt(x)
-- acos(x)       floor(x)       sub(x,y)
-- acosh(x)       idiv(x,y)       tan(x)
-- add(x,y)       inv(x)       tanh(x)
-- asin(x)       iseven(x)       tonumber(x)
-- asinh(x)       isint(x)       tostring(x,[n,exp])
-- atan(x)       isodd(x)       version
-- atan2(y,x)       log(x)
-- atanh(x)       log10(x)

print("\nSquare root of 2")
lmapm.digits(65)
print("math.sqrt(2) ", math.sqrt(2))
print("lmapm.sqrt(2) ", lmapm.sqrt(2))
print(lmapm.version)

7. Script Console

Comet integrates a Lua script console (Menu View / Script Console). You can use it as an interactive programming console to learn or quickly test concepts. To use the script console, simply write a Lua valid statements (example: x = math.pi/3; y = math.sin(x); print(y); ), and press ENTER. You can enter multi-line statements: just press SHIFT+ENTER after each line and ENTER to run. You can use any standard Lua function or Comet module.

8. Debugging

Comet provides debugging capabilities on Windows and Linux: you can set breakpoints in the code (Menu Run/Add Breakpoint or the toolbar corresponding button) and view the current variables set in the Watch window. To start debugging, click Debug (or Menu Run/Debug or Ctrl+F12). Debugger can 'Step Into' or 'Step Over' on a call depending on the option set by user in Menu Run/Step Into (unchecked for 'Step Over').

9. Changelog

Version 1.4 Build 1701
• Improvements and bugfixes:
plot module updated.
Performance improved.
Serial (RS232) module added for instrumentation.
Added library for Arbitrary Precision Math (MAPM) by Michael C. Ring.
Lua print function implementation updated.

Version 1.2 Build 1601
• Minor improvements and bugfixes:
New tool added: SigmaCalculator, an advanced mathematical expression-based calculator.
New ‘Tools’ menu including the external tools options and SigmaCalculator.
LPeg pattern matching module added.
AES encryption module added.
'Find/Replace in files' functions improved under Linux.
Explorer minor changes in the move/replace functions.
Drag/Drop files fully supported under Linux.
Transparency of the window can now be adjusted.

Version 1.0 Build 1512
• Unified Android/Linux/Windows version (the same code runs on all supported platforms, except for the linear algebra and network functions not available on Android).
• Network module (socket namespace) for Linux and Windows (BSD socket style).
• Linear Algebra module based on the well-established Lapack routines.
• Ordinary differential equation solver.
• Mathematical optimization module.
• PDF User’s Guide.

10. Specifications

10.1 System requirements

Comet runs on PC with Windows™ XP, Vista or Windows 7/8/10, or Linux 32bit or 64bit, or Android system.

The basic hardware requirements for PC are:

· Pentium or better microprocessor.

· 256 MB RAM.

· 20 MB of hard disk space.

· VGA monitor with 800x600 or higher resolution.

10.2 Contact

http://www.hamady.org

sidi@hamady.org

10.3 Copyright

Comet:
Copyright(C) 2010-2017 Dr. Sidi HAMADY
http://www.hamady.org
sidi@hamady.org
Comet is protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Comet is free of charge only for non-commercial use.
Dr. Sidi HAMADY expressly disclaims any warranty for Comet. Comet is provided ‘As Is’ without any express or implied warranty of any kind, including but not limited to any warranties of merchantability, noninfringement, or fitness of a particular purpose.
Comet may not be redistributed without authorization of the author.

Comet for Linux and Windows uses:
The Lua Programming Language, (C) 1994–2013 Lua.org, PUC-Rio.
The Lua Just-In-Time Compiler, (C) 2005-2015 Mike Pall.
The f2c'ed version of Lapack, (C) 1992-2008 The University of Tennessee.
The LIS linear solvers, (C) The SSI Project, Kyushu University, Japan.
The ODE solver developed by Scott D. Cohen and Alan C. Hindmarsh @ LLNL.
The Scintilla Component, (C) 1998-2004 Neil Hodgson.
The wxWidgets GUI toolkit, (C) 1992-2013 the wxWidgets team.

 Copyright(C) 2010-2017 Dr. Sidi HAMADY