Skip to content

Commit

Permalink
general cleanup
Browse files Browse the repository at this point in the history
better error reporting
add progressbar to linker
  • Loading branch information
SnarkyClark committed Nov 28, 2009
1 parent 9400134 commit 9b1aba2
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 295 deletions.
10 changes: 5 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
LuaDesk

A basic script host for rapid desktop application development using Lua & IUP. Currently focused on Windows deployment, but can be adapated to GTK+ and Motif.
A basic script host for rapid desktop application development using Lua & IUP. Currently focused on Windows deployment, but can be adapted to GTK+ and Motif.

Summary:

Using LuaDesk, one can build a stand-alone, interactive executable with a GUI that has no external dependencies using the Lua language. Functionality think of it as VB for ubergeeks. The primary purpose is to allow rapid (rabid?) application development for small to medium-sized portable desktop "applets" or "vertical market" programs. Current uses include a basic POS system, postage meter interface, and various datamining/reporting tools.
Using LuaDesk, one can build a stand-alone, interactive executable with a GUI that has no external dependencies using the Lua language. Functionally think of it as VB for ubergeeks - but no compiler is needed. The primary purpose is to allow rapid (rabid?) application development for small to medium-sized portable desktop "applets" or "vertical market" programs. Current uses include a basic POS system, postage meter interface, and various data-mining/reporting tools.

Given that IUP is statically linked, this means that life gets much easier when we statically link ALL third-party Lua libraries used by the scripts. It also gives the benefit of a single file deployment/installation. Downsides are a more complicated build/project and a bunch of extra work. Currently included libraries are: LuaFileSystem and LuaCurl. Future additions will be a XML parser and LPEG. LuaSQL & LuaSocket are being looked at, but may take awhile. Feel free to help out ;)

Howto:
How to:

So how do you turn your own (or the example) scripts into an executable? Just run the luadesk executable, and it will launch the embedded "linker" script. Follow the prompts to select one or more Lua scripts (plain-text or compiled) and specify an output file.
So how do you turn your own (or on of the example) scripts into an executable? Just run the luadesk executable, and it will launch the embedded "linker" script. Follow the prompts to select one or more Lua scripts (plain-text or compiled) and specify an output file. The way it works internally is modeled after how self-extracting archives work. All "linked" files are appended to the host executable and a table of contents is created at the end. But instead of writing each packaged file to storage when the host is launched, each linked file (Lua script in this case) is run through the Lua Virtual Machine.

Any syntax or runtime script errors will be displayed as a popup when you run the output executable (and will cause the program to immediately exit). Have fun!
Any syntax or runtime script errors will be displayed as a pop-up when you run the output executable (and will cause the program to immediately exit). Have fun!

References:

Expand Down
Binary file modified bin/Debug/luadesk.exe
Binary file not shown.
Binary file modified bin/Release/luadesk.exe
Binary file not shown.
Binary file modified examples/hello_world.exe
Binary file not shown.
Binary file added examples/progress.exe
Binary file not shown.
46 changes: 46 additions & 0 deletions examples/progress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function idle_cb()
local value = gauge.value
value = value + 0.01;
ldesk.msleep(10)
if value > 1.0 then
value = 0.0
ldesk.sleep(1)
end
gauge.value = value
return iup.DEFAULT
end

function main(args)
local value = 0
gauge = iup.progressbar {max = 100}
label = iup.label { title = string.format("value = %f...", value) }
dlg = iup.dialog{iup.vbox{gauge, label}; title = "IupGauge"}
dlg.size = "QUARTERxEIGHTH"

local value = 0.0
dlg:showxy(iup.CENTER, iup.CENTER)
for i = 1, 1000, 1 do
value = value + 1.0
if value > 100.0 then
value = 0.0
ldesk.sleep(1)
end
gauge.value = value * 1.20
label.title = string.format("value = %f...", value)
ldesk.msleep(50)
iup.LoopStep()
end
dlg:hide()
dlg:destroy()

--[[
-- Registers idle callback
iup.SetIdle(idle_cb)
dlg:showxy(iup.CENTER, iup.CENTER)
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
iup.MainLoop()
end
]]

end
20 changes: 20 additions & 0 deletions hton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef HTON_H_INCLUDED
#define HTON_H_INCLUDED

#if defined(BIG_ENDIAN)
#define htons(A) (A)
#define htonl(A) (A)
#define ntohs(A) (A)
#define ntohl(A) (A)
#else
#define htons(A) ((((uint16_t)(A) & 0xff00) >> 8) | \
(((uint16_t)(A) & 0x00ff) << 8))
#define htonl(A) ((((uint32_t)(A) & 0xff000000) >> 24) | \
(((uint32_t)(A) & 0x00ff0000) >> 8) | \
(((uint32_t)(A) & 0x0000ff00) << 8) | \
(((uint32_t)(A) & 0x000000ff) << 24))
#define ntohs htons
#define ntohl htonl
#endif

#endif // HTON_H_INCLUDED
67 changes: 67 additions & 0 deletions libluadesk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <stdint.h>

#include <iup.h>
#include "hton.h"
#include "libluadesk.h"

#include <unistd.h>
#define msleep(msec) (usleep((msec) * 1000))

int L_htons(lua_State *L) {
uint16_t n = (uint16_t)luaL_checkint(L, 1);
n = htons(n);
lua_pushlstring(L, (const char*)&n, 2);
return 1;
}

int L_htonl(lua_State *L) {
uint32_t n = (uint32_t)luaL_checklong(L, 1);
n = htonl(n);
lua_pushlstring(L, (const char*)&n, 4);
return 1;
}

int L_ntohs(lua_State *L) {
uint16_t n = *(uint16_t*)luaL_checkstring(L, 1);
n = htons(n);
lua_pushnumber(L, n);
return 1;
}

int L_ntohl(lua_State *L) {
uint32_t n = *(uint32_t*)luaL_checkstring(L, 1);
n = htonl(n);
lua_pushnumber(L, n);
return 1;
}

int L_msleep(lua_State *L) {
uint32_t i;
uint32_t n = (uint32_t)luaL_checklong(L, 1);
for (i = 0; i < n; i++) {
usleep(1000);
if (IupLoopStep() == IUP_CLOSE) break;
}
return 0;
}

int L_sleep(lua_State *L) {
uint32_t i;
uint32_t n = (uint32_t)luaL_checklong(L, 1);
for (i = 0; i < n * 100; i++) {
usleep(1000);
if (IupLoopStep() == IUP_CLOSE) break;
}
return 0;
}

const luaL_Reg R_ld_functions[] = {
{"htons", L_htons},
{"htonl", L_htonl},
{"ntohs", L_htons},
{"ntohl", L_htonl},
{"msleep", L_msleep},
{"sleep", L_sleep},
{NULL, NULL}
};

10 changes: 10 additions & 0 deletions libluadesk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LIBLUADESK_H_INCLUDED
#define LIBLUADESK_H_INCLUDED

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

extern const luaL_Reg R_ld_functions[];

#endif // LIBLUADESK_H_INCLUDED
Loading

0 comments on commit 9b1aba2

Please sign in to comment.