summaryrefslogtreecommitdiffstats
path: root/src/lua.c
diff options
context:
space:
mode:
authormongo <andmarti@gmail.com>2017-03-17 14:58:43 -0300
committermongo <andmarti@gmail.com>2017-03-17 14:58:43 -0300
commite78c2f8d465023581f8514a419239cd4cb748ebd (patch)
tree4ca3e83a9f59f3b679f9aa128465d9e3e89e5231 /src/lua.c
parentf5214cedaaba3b7983eb852bd041b35b378b1f30 (diff)
parent75fae2480269e6edd54a6b51bfd7bdfe1d7fa4b9 (diff)
Merge branch 'freeze' of https://github.com/andmarti1424/sc-im into freeze
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/lua.c b/src/lua.c
index 834a787..b70cfa2 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -28,7 +28,6 @@
#include "screen.h"
#include "conf.h"
-
extern FILE * fdoutput;
extern WINDOW * input_win;
@@ -127,7 +126,6 @@ static int l_sc (lua_State *L) {
return 0;
}
-
static int l_colrow2a(lua_State *L) {
int c, r;
char buf[16];
@@ -139,7 +137,6 @@ static int l_colrow2a(lua_State *L) {
return 1;
}
-
static int l_colrow(lua_State *L) {
char buf[16];
char *val;
@@ -242,8 +239,6 @@ LC_NUMBER2(curcol,curcol)
LC_NUMBER2(maxcols,maxcols)
LC_NUMBER2(maxrows,maxrows)
-
-
static const luaL_reg sclib[] = {
{ "lgetnum", l_getnum },
{ "lsetnum", l_setnum },
@@ -260,20 +255,23 @@ static const luaL_reg sclib[] = {
{NULL,NULL}
};
-
-
void doLuainit() {
- L = luaL_newstate(); /* Create Lua state variable */
- luaL_openlibs(L); /* Load Lua libraries */
+ char buffer[PATHLEN];
+ char buffer1[PATHLEN];
- luaL_register(L, "sc", sclib);
+ L = luaL_newstate(); /* Create Lua state variable */
+ luaL_openlibs(L); /* Load Lua libraries */
- if (luaL_loadfile(L, "init.lua")) { /* Load but don't run the Lua script */
- fprintf(stderr, "\nWarning :\n Couldn't load init.lua: %s\n\n", lua_tostring(L,-1));
- return;
+ sprintf(buffer,"lua/init.lua");
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) { /* Load but don't run the Lua script */
+ fprintf(stderr, "\nWarning :\n Couldn't load init.lua: %s\n\n", lua_tostring(L,-1));
+ return;
+ }
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ fprintf(stderr, "\nFATAL ERROR:\n Couldn't initialized Lua: %s\n\n", lua_tostring(L,-1));
}
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- fprintf(stderr, "\nFATAL ERROR:\n Couldn't initialized Lua: %s\n\n", lua_tostring(L,-1));
+ luaL_register(L, "sc", sclib); /* Load SC specific LUA commands after init.lua exec*/
return;
}
@@ -285,32 +283,34 @@ void doLuaclose() {
char * doLUA( struct enode * se) {
char * cmd;
-
+ char buffer[PATHLEN];
+ char buffer1[PATHLEN];
cmd = seval(NULL, se->e.o.left);
- if (luaL_loadfile(L, cmd)) /* Load but don't run the Lua script */
- bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ sprintf(buffer,"lua/%s",cmd);
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
+ bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
-
- /* Tell what function to run */
- // lua_getglobal(L, "tellme");
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ /* Tell what function to run */
+ // lua_getglobal(L, "tellme");
+ }
return 0;
}
-
void doLuaTriger() {
- if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
- return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
+ return;
+ //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- lua_getglobal(L, "trigger"); /* Tell what function to run */
+ lua_getglobal(L, "trigger"); /* Tell what function to run */
//sc_debug("In C, calling Lua");
if (lua_pcall(L, 0, 0, 0)) /* Run the function */
@@ -346,27 +346,32 @@ we assume file and function ist correct other lua throught an error
void doLuaTrigger_cell(struct ent *p, int flags) {
int row,col;
struct trigger *trigger = p->trigger;
+ char buffer[PATHLEN];
+ char buffer1[PATHLEN];
row = p->row;
col = p->col;
- if (luaL_loadfile(L, trigger->file)) /* Load but don't run the Lua script */
- return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ sprintf(buffer,"lua/%s",trigger->file);
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
+ return;
+ //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- lua_getglobal(L, trigger->function); /* Tell what function to run */
+ lua_getglobal(L, trigger->function); /* Tell what function to run */
- lua_pushinteger(L,col);
- lua_pushinteger(L,row);
- lua_pushinteger(L, flags);
- //sc_debug("In C, calling Lua");
- if (lua_pcall(L, 3, 0, 0)) /* Run the function */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- //sc_debug("Back in C again");
- return;
+ lua_pushinteger(L,col);
+ lua_pushinteger(L,row);
+ lua_pushinteger(L, flags);
+ //sc_debug("In C, calling Lua");
+ if (lua_pcall(L, 3, 0, 0)) /* Run the function */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ //sc_debug("Back in C again");
+ }
+ return;
}
#endif