diff --git a/build_plugin.sh b/build_plugin.sh deleted file mode 100755 index 437f9b58..00000000 --- a/build_plugin.sh +++ /dev/null @@ -1 +0,0 @@ -gcc -g sample_plugin.c -shared -o data/plugins/sample.so diff --git a/data/core/init.lua b/data/core/init.lua index 1cb98979..e05d5c2b 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -426,8 +426,6 @@ function core.init() NagView = require "core.nagview" DocView = require "core.docview" Doc = require "core.doc" - local PluginTest = require "plugins.sample" - print(PluginTest.example) if PATHSEP == '\\' then USERDIR = common.normalize_path(USERDIR) diff --git a/data/core/start.lua b/data/core/start.lua index 7658d6c7..0bbaadee 100644 --- a/data/core/start.lua +++ b/data/core/start.lua @@ -22,6 +22,7 @@ package.path = USERDIR .. '/?/init.lua;' .. package.path local dynamic_suffix = MACOS and 'lib' or (WINDOWS and 'dll' or 'so') package.cpath = DATADIR .. '/?.' .. dynamic_suffix .. ';' .. package.cpath +package.cpath = USERDIR .. '/?.' .. dynamic_suffix .. ';' .. package.cpath package.searchers[3] = function(modname) local s,e = 0 repeat diff --git a/generate_header.sh b/generate_header.sh deleted file mode 100755 index fb03e712..00000000 --- a/generate_header.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# Takes lua folder, outputs a header file that includes all the necessary macros for writing a lite plugin. -# Takes a minimal approach, and strips out problematic functions. Should be good enough for most purposes. - -echo "// This file was automatically generated by generate_header.sh. Do not modify directly." -echo "#include " -echo "typedef struct lua_State lua_State; typedef double lua_Number; typedef int (*lua_CFunction)(lua_State*); typedef ptrdiff_t lua_Integer;" -echo "typedef unsigned long lua_Unsigned; typedef struct luaL_Buffer luaL_Buffer; typedef struct luaL_Reg luaL_Reg; typedef struct lua_Debug lua_Debug;" -echo "typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);" -echo "typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);" -echo "typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);" -grep -h "^LUA\(LIB\)*_API" $1/*.h | sed "s/LUA\(LIB\)*_API //" | sed "s/(lua/(*lua/" | grep -v ",\s*$" | sed "s/^/static /" -grep -h "#define luaL*_" $1/*.h | grep -v "\\\s*$" | grep -v "\(assert\|lock\)" | grep -v "\(asm\|int32\)" | grep -v "#define lua_number2integer(i,n)\s*lua_number2int(i, n)" -echo "#define IMPORT_SYMBOL(name, ret, ...) name = (ret (*)(__VA_ARGS__))symbol(#name)" -echo "static void lite_init_plugin(void* (*symbol(const char*))) {" -grep -h "^LUA\(LIB\)*_API" $1/*.h | sed "s/LUA\(LIB\)*_API //" | sed "s/(lua/(*lua/" | grep -v ",\s*$" | sed "s/^\([^)]*\)(\*\(lua\w*\))\s*(/\tIMPORT_SYMBOL(\2, \1,/" -echo "}" diff --git a/lite_plugin_api.h b/resources/lite_xl_plugin_api.h similarity index 91% rename from lite_plugin_api.h rename to resources/lite_xl_plugin_api.h index b6c03204..7ac9c5e8 100644 --- a/lite_plugin_api.h +++ b/resources/lite_xl_plugin_api.h @@ -1,4 +1,30 @@ -// This file was automatically generated by generate_header.sh. Do not modify directly. +#ifndef LITE_XL_PLUGIN_API +#define LITE_XL_PLUGIN_API +/* This file was automatically generated by the below code. Do not modify directly. +#!/bin/sh +# Takes lua folder, outputs a header file that includes all the necessary macros for writing a lite plugin. +# Takes a minimal approach, and strips out problematic functions. Should be good enough for most purposes. + +echo "#ifndef LITE_XL_PLUGIN_API" +echo "#define LITE_XL_PLUGIN_API" +echo "/* This file was automatically generated by the below code. Do not modify directly." +cat $0 +echo "*""/" +echo "#include " +echo "typedef struct lua_State lua_State; typedef double lua_Number; typedef int (*lua_CFunction)(lua_State*); typedef ptrdiff_t lua_Integer;" +echo "typedef unsigned long lua_Unsigned; typedef struct luaL_Buffer luaL_Buffer; typedef struct luaL_Reg luaL_Reg; typedef struct lua_Debug lua_Debug;" +echo "typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);" +echo "typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);" +echo "typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);" +LUA_HEADERS=`pkg-config --cflags lua5.2 | sed 's/^-I//' | sed 's/$/\/*.h/'` +grep -h "^LUA\(LIB\)*_API" $LUA_HEADERS | sed "s/LUA\(LIB\)*_API //" | sed "s/(lua/(*lua/" | grep -v ",\s*$" | sed "s/^/static /" +grep -h "#define luaL*_" $LUA_HEADERS | grep -v "\\\s*$" | grep -v "\(assert\|lock\)" | grep -v "\(asm\|int32\)" | grep -v "#define lua_number2integer(i,n)\s*lua_number2int(i, n)" +echo "#define IMPORT_SYMBOL(name, ret, ...) name = (ret (*)(__VA_ARGS__))symbol(#name)" +echo "static void lite_init_plugin(void* (*symbol(const char*))) {" +grep -h "^LUA\(LIB\)*_API" $LUA_HEADERS | sed "s/LUA\(LIB\)*_API //" | sed "s/(lua/(*lua/" | grep -v ",\s*$" | sed "s/^\([^)]*\)(\*\(lua\w*\))\s*(/\tIMPORT_SYMBOL(\2, \1,/" +echo "}" +echo "#endif" +*/ #include typedef struct lua_State lua_State; typedef double lua_Number; typedef int (*lua_CFunction)(lua_State*); typedef ptrdiff_t lua_Integer; typedef unsigned long lua_Unsigned; typedef struct luaL_Buffer luaL_Buffer; typedef struct luaL_Reg luaL_Reg; typedef struct lua_Debug lua_Debug; @@ -142,10 +168,6 @@ static void (*luaL_openlibs) (lua_State *L); #define luaL_addsize(B,s) ((B)->n += (s)) #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) -#define lua_number2int(i,n) ((i)=(int)(n)) -#define lua_number2integer(i,n) ((i)=(lua_Integer)(n)) -#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) -#define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) #define lua_h #define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i)) #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) @@ -298,3 +320,4 @@ static void lite_init_plugin(void* (*symbol(const char*))) { IMPORT_SYMBOL(lua_gethookcount, int ,lua_State *L); IMPORT_SYMBOL(luaL_openlibs, void ,lua_State *L); } +#endif diff --git a/sample_plugin.c b/sample_plugin.c deleted file mode 100644 index 96e021c9..00000000 --- a/sample_plugin.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include "lite_plugin_api.h" - -int lua_open_sample(lua_State* L, void* (*symbol(const char*))) { - lite_init_plugin(symbol); - lua_createtable(L, 0, 0); - lua_pushstring(L, "value"); - lua_setfield(L, -2, "example"); - return 1; -}