-rw-r--r-- | graph-init.lua | 2 | ||||
-rw-r--r-- | gslext.lua | 6 | ||||
-rw-r--r-- | iter.lua (renamed from base.lua) | 11 | ||||
-rw-r--r-- | lua-graph.c | 6 | ||||
-rw-r--r-- | lua-graph.h | 2 | ||||
-rw-r--r-- | lua-gsl.c | 19 | ||||
-rw-r--r-- | lua-gsl.h | 3 | ||||
-rw-r--r-- | lua-rng.c | 1 | ||||
-rw-r--r-- | matrix.lua (renamed from matrix-init.lua) | 7 | ||||
-rw-r--r-- | num.lua (renamed from misc.lua) | 4 | ||||
-rw-r--r-- | randist.c | 1 | ||||
-rw-r--r-- | sf.c | 1 |
diff --git a/graph-init.lua b/graph-init.lua index f6e63c5f..e0933e99 100644 --- a/graph-init.lua +++ b/graph-init.lua @@ -1,7 +1,7 @@ local floor = math.floor -local lua_index_style = config.lua_index_style +local lua_index_style = gslsh.lua_index_style function graph.ipath(f) local ln = graph.path(f()) diff --git a/gslext.lua b/gslext.lua index 21f6e2ef..3ded2d77 100644 --- a/gslext.lua +++ b/gslext.lua @@ -1,8 +1,8 @@ -- load initialization files for GSL Shell -require('base') -require('matrix-init') -require('misc') +require('iter') +require('matrix') +require('num') require('integ-init') require('fft-init') require('graph-init') @@ -20,11 +20,9 @@ local cat = table.concat local fmt = string.format -local gsl_type = num.type +local gsl_type = gslsh.type -config = { - lua_index_style = true, -} +gslsh.lua_index_style = true function math.divmod(n, p) local r = n % p @@ -62,7 +60,8 @@ tos = function (t, maxdepth) elseif tp == 'string' then return fmt('%q', t) elseif tp == 'userdata' then - local ftostr = getmetatable(t).__tostring + local mt = getmetatable(t) + local ftostr = mt and mt.__tostring if ftostr then return ftostr(t) else if gsl_type then return fmt('<%s: %p>', gsl_type(t), t) @@ -138,4 +137,4 @@ iter = { isum = isum, } -package.loaded['iter'] = iter +return iter diff --git a/lua-graph.c b/lua-graph.c index a35c8aeb..161330ba 100644 --- a/lua-graph.c +++ b/lua-graph.c @@ -30,8 +30,8 @@ static const struct luaL_Reg methods_dummy[] = {{NULL, NULL}}; -int -luaopen_graph (lua_State *L) +void +register_graph (lua_State *L) { window_registry_prepare (L); @@ -42,5 +42,5 @@ luaopen_graph (lua_State *L) window_register (L); plot_register (L); - return 1; + lua_pop(L, 1); } diff --git a/lua-graph.h b/lua-graph.h index b6f49ed1..3faeb21a 100644 --- a/lua-graph.h +++ b/lua-graph.h @@ -5,6 +5,6 @@ #define MLUA_GRAPHLIBNAME "graph" #endif -extern int luaopen_graph (lua_State *L); +extern void register_graph (lua_State *L); #endif @@ -34,30 +34,25 @@ static int gsl_shell_lua_registry (lua_State *L); #endif -static const struct luaL_Reg gsl_shell_functions[] = { #ifdef GSL_SHELL_DEBUG +static const struct luaL_Reg gsl_shell_functions[] = { {"registry", gsl_shell_lua_registry}, -#endif - {NULL, NULL} -}; - -static const struct luaL_Reg matrix_functions[] = { {NULL, NULL} }; +#endif int luaopen_gsl (lua_State *L) { gsl_set_error_handler_off (); - luaopen_graph (L); - lua_pop (L, 1); - - luaL_register (L, MLUA_GSLLIBNAME, gsl_shell_functions); - luaL_register (L, NULL, gs_type_functions); - + luaL_register (L, "gslsh", gs_type_functions); +#ifdef GSL_SHELL_DEBUG + luaL_register (L, NULL, gsl_shell_functions); +#endif lua_pop (L, 1); + register_graph (L); rng_register (L); randist_register (L); sf_register (L); @@ -1,9 +1,6 @@ #ifndef LUA_GSL_H #define LUA_GSL_H -#define MLUA_GSLLIBNAME "num" -#define MLUA_MATRIXLIBNAME "matrix" - extern int luaopen_gsl (lua_State *L); #endif @@ -165,4 +165,5 @@ rng_register (lua_State *L) /* gsl module registration */ luaL_register (L, "rng", rng_functions); + lua_pop(L, 1); } diff --git a/matrix-init.lua b/matrix.lua index aba049c1..04ad6973 100644 --- a/matrix-init.lua +++ b/matrix.lua @@ -1,5 +1,5 @@ -local ffi = require 'ffi' +local ffi = require 'ffi' local gsl = require 'gsl' local sqrt, abs = math.sqrt, math.abs @@ -8,7 +8,7 @@ local format = string.format local check = require 'check' local is_integer, is_real = check.is_integer, check.is_real -local lua_index_style = config.lua_index_style +local lua_index_style = gslsh.lua_index_style local gsl_matrix = ffi.typeof('gsl_matrix') local gsl_matrix_complex = ffi.typeof('gsl_matrix_complex') @@ -603,7 +603,6 @@ local function matrix_new_copy(m) return m:copy() end - matrix = { new = matrix_new, cnew = matrix_cnew, @@ -933,4 +932,4 @@ matrix.tr = function(a) matrix.def = matrix_def matrix.cdef = matrix_cdef -package.loaded['matrix'] = matrix +return matrix @@ -1,6 +1,8 @@ local template = require 'template' +num = {} + function num.ode(spec) local required = {N= 'number', eps_abs= 'number'} local defaults = {eps_rel = 0, a_y = 1, a_dydt = 0} @@ -57,3 +59,5 @@ function num.nlinfit(spec) return s end + +return num @@ -151,4 +151,5 @@ void randist_register (lua_State *L) { luaL_register (L, "rnd", randist_functions); + lua_pop(L, 1); } @@ -86,4 +86,5 @@ void sf_register (lua_State *L) { luaL_register (L, "sf", sf_functions); + lua_pop(L, 1); } |