Moving things into final positions.

This commit is contained in:
Adam Harrison 2021-09-16 15:47:12 -04:00
parent 377ce1cd06
commit 2987554097
6 changed files with 29 additions and 35 deletions

View File

@ -1 +0,0 @@
gcc -g sample_plugin.c -shared -o data/plugins/sample.so

View File

@ -426,8 +426,6 @@ function core.init()
NagView = require "core.nagview" NagView = require "core.nagview"
DocView = require "core.docview" DocView = require "core.docview"
Doc = require "core.doc" Doc = require "core.doc"
local PluginTest = require "plugins.sample"
print(PluginTest.example)
if PATHSEP == '\\' then if PATHSEP == '\\' then
USERDIR = common.normalize_path(USERDIR) USERDIR = common.normalize_path(USERDIR)

View File

@ -22,6 +22,7 @@ package.path = USERDIR .. '/?/init.lua;' .. package.path
local dynamic_suffix = MACOS and 'lib' or (WINDOWS and 'dll' or 'so') local dynamic_suffix = MACOS and 'lib' or (WINDOWS and 'dll' or 'so')
package.cpath = DATADIR .. '/?.' .. dynamic_suffix .. ';' .. package.cpath package.cpath = DATADIR .. '/?.' .. dynamic_suffix .. ';' .. package.cpath
package.cpath = USERDIR .. '/?.' .. dynamic_suffix .. ';' .. package.cpath
package.searchers[3] = function(modname) package.searchers[3] = function(modname)
local s,e = 0 local s,e = 0
repeat repeat

View File

@ -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 <stddef.h>"
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 "}"

View File

@ -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 <stddef.h>"
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 <stddef.h> #include <stddef.h>
typedef struct lua_State lua_State; typedef double lua_Number; typedef int (*lua_CFunction)(lua_State*); typedef ptrdiff_t lua_Integer; 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; 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_addsize(B,s) ((B)->n += (s))
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) #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_h
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i)) #define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) #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(lua_gethookcount, int ,lua_State *L);
IMPORT_SYMBOL(luaL_openlibs, void ,lua_State *L); IMPORT_SYMBOL(luaL_openlibs, void ,lua_State *L);
} }
#endif

View File

@ -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;
}