cleanups, reworking signal system

This commit is contained in:
Axel Kittenberger 2018-05-13 14:13:54 +02:00
parent 693a07e529
commit e6e9ba7d9c
7 changed files with 78 additions and 34 deletions

View File

@ -446,7 +446,7 @@ main1( int argc, char *argv[] )
}
// loads the user enivornment
lua_getglobal( L, "userENV" );
lua_getglobal( L, "userenv" );
lua_setupvalue( L, -2, 1 );
if( lua_pcall( L, 0, LUA_MULTRET, 0) )

View File

@ -783,7 +783,7 @@ mci_load_default(
// loads the user enivornment
// the default sync implementations are actually not priviledged in any way
lua_getglobal( L, "userENV" );
lua_getglobal( L, "userenv" );
lua_setupvalue( L, -2, 1 );
// prepares the default sync implementations

View File

@ -26,6 +26,11 @@ local function sigint
( )
print( 'GOT AN INT SIGNAL' )
for _, s in ipairs( syncs )
do
print( 'a sync' )
end
os.exit( 1 )
end

View File

@ -375,7 +375,7 @@ function mci.initialize
)
-- Checks if user overwrote the settings function.
-- ( was Lsyncd <2.1 style )
if userENV.settings ~= settings
if userenv.settings ~= user.settings
then
log(
'Error',
@ -386,7 +386,7 @@ function mci.initialize
os.exit( -1 )
end
if userENV.init then userENV.init( ) end
if userenv.init then userenv.init( ) end
lastReportedWaiting = false
@ -426,7 +426,7 @@ function mci.initialize
--
if uSettings.statusInterval == nil
then
uSettings.statusInterval = userENV.default.statusInterval
uSettings.statusInterval = userenv.default.statusInterval
end
-- makes sure the user gave Lsyncd anything to do

View File

@ -173,19 +173,6 @@ local function add
(
config
)
-- Checks if user overwrote the settings function.
-- ( was Lsyncd < 2.1 style )
if userENV.settings ~= settings
then
log(
'Error',
'Do not use settings = { ... }\n'..
' please use settings{ ... } (without the equal sign)'
)
os.exit( -1 )
end
-- Creates a new config table which inherits all keys/values
-- from integer keyed tables
local uconfig = config
@ -195,7 +182,7 @@ local function add
inherit( config, uconfig )
-- last and least defaults are inherited
inherit( config, userENV.default )
inherit( config, userenv.default )
local inheritSettings =
{

View File

@ -15,15 +15,32 @@ then
end
user = { }
--
-- Main utility to create new observations.
--
-- Returns an Inlet to that sync.
--
function sync
user.sync =
function
(
opts
)
-- Checks if user overwrote the settings function.
-- ( was Lsyncd < 2.1 style )
if userenv.settings ~= user.settings
then
log(
'Error',
'Do not use settings = { ... }\n'..
' please use settings{ ... } (without the equal sign)'
)
os.exit( -1 )
end
if lsyncdStatus ~= 'init'
then
error( 'Sync can only be created during initialization.', 2 )
@ -36,7 +53,8 @@ end
--
-- Spawns a new child process.
--
function spawn
user.spawn =
function
(
agent, -- the reason why a process is spawned.
-- a delay or delay list for a sync
@ -130,7 +148,8 @@ end
--
-- Spawns a child process using the default shell.
--
function spawnShell
user.spawnShell =
function
(
agent, -- the delay(list) to spawn the command for
command, -- the shell command
@ -143,7 +162,8 @@ end
--
-- Observes a filedescriptor.
--
function observefd
user.observefd =
function
(
fd, -- file descriptor
ready, -- called when fd is ready to be read
@ -156,7 +176,8 @@ end
--
-- Stops observeing a filedescriptor.
--
function nonobservefd
user.nonobservefd =
function
(
fd -- file descriptor
)
@ -170,7 +191,7 @@ end
-- Use now() to receive current timestamp
-- add seconds with '+' to it
--
alarm = UserAlarms.alarm
user.alarm = UserAlarms.alarm
--
@ -193,7 +214,8 @@ local settingsCheckgauge =
--
-- The settings call
--
function settings
user.settings =
function
(
a1 -- a string for getting a setting
-- or a table of key/value pairs to set these settings
@ -227,3 +249,28 @@ function settings
end
end
--
-- Provides a way for user scripts to browse (and alter) active sync list.
--
user.syncs =
( function( )
local mt =
{
__ipairs =
function
( )
print( 'syncs.ipairs!!!' )
end
}
-- public interface
local intf = {
add = sync
}
setmetatable( intf, mt )
return intf
end ) ( )

View File

@ -11,7 +11,7 @@
-- License: GPLv2 (see COPYING) or any later version
-- Authors: Axel Kittenberger <axkibe@gmail.com>
--
userENV =
userenv =
{
-- generic lua stuff to be available
_VERSION = _VERSION,
@ -51,19 +51,24 @@ userENV =
-- lsyncd mantle available to user scripts
Array = Array,
Queue = Queue,
settings = settings,
spawn = spawn,
spawnShell = spawnShell,
sync = sync,
-- user interface functions and objects
alarm = user.alarm,
nonobservefs = user.nonobserfd,
observefd = user.observefd,
settings = user.settings,
spawn = user.spawn,
spawnShell = user.spawnShell,
sync = user.sync,
syncs = user.syncs,
-- lsyncd core available to user scripts
-- FIXME always make wrappers
log = core.log,
nonobservefs = core.nonobserfd,
now = core.now,
observefd = core.observefd,
readdir = core.readdir,
terminate = core.terminate
}
userENV._G = userENV
userenv._G = userenv