├── .gitignore ├── README.md ├── SDL2 ├── SDL2.lua ├── build.lua └── make.sh ├── VTFLib ├── VTFLib.lua ├── build.lua └── make.sh ├── assimp ├── assimp.lua ├── build.lua └── make.sh ├── bgfx ├── .gitignore ├── bgfx.lua ├── build.lua └── make.sh ├── bullet ├── build.lua ├── bullet.lua └── make.sh ├── curses ├── build.lua ├── curses.lua ├── make.sh └── readme.md ├── enet ├── build.lua ├── enet.lua └── make.sh ├── ffibuild.lua ├── freeimage ├── build.lua ├── freeimage.lua └── make.sh ├── freetype ├── build.lua ├── freetype.lua └── make.sh ├── generic.sh ├── glfw ├── build.lua ├── glfw.lua └── make.sh ├── graphene ├── build.lua ├── graphene.lua └── make.sh ├── libarchive ├── build.lua ├── libarchive.lua └── make.sh ├── libmp3lame ├── build.lua ├── libmp3lame.lua └── make.sh ├── libsndfile ├── build.lua ├── libsndfile.lua └── make.sh ├── luajit ├── Makefile ├── build.lua └── luajit.lua ├── luajit_forks ├── .gitignore ├── build.lua └── make.sh ├── luaossl ├── build.lua └── make.sh ├── luasec ├── build.lua └── make.sh ├── luasec_nix ├── build.lua └── make.sh ├── luasocket ├── build.lua └── make.sh ├── mpg123 ├── build.lua ├── make.sh └── mpg123.lua ├── ode ├── build.lua ├── make.sh └── ode.lua ├── openal ├── al.lua ├── alc.lua ├── build.lua ├── make.sh └── openal.lua ├── opengl ├── build.lua ├── build_from_xml.lua ├── make.sh ├── opengl.lua └── readme.md ├── openssl ├── build.lua └── make.sh ├── purple ├── Makefile ├── README.md ├── build.lua ├── callbacks.lua ├── goura.c ├── main.lua ├── purple.lua └── temp.c ├── steamworks ├── build.lua ├── build_from_json.lua ├── make.sh ├── readme.md └── steamworks.lua └── vulkan ├── build.lua ├── make.sh └── vulkan.lua /.gitignore: -------------------------------------------------------------------------------- 1 | *repo/ 2 | *include/ 3 | *result 4 | 5 | # temp files 6 | *.nix 7 | 8 | # Object files 9 | *.o 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | 15 | # Shared objects (inc. Windows DLLs) 16 | *.dll 17 | *.so 18 | *.so.* 19 | *.dylib 20 | 21 | # Executables 22 | *.exe 23 | *.out 24 | *.app 25 | *.directory 26 | *.DS_Store 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ffibuild is a utility to generate FFI bindings for LuaJIT. It can use the Nix package manager to automatically setup the build environment and build the library you want. 2 | 3 | There are also helper functions to build more manually, but this assumes you have the required packages to build. 4 | 5 | ffibuild is used on Linux and macOS. Because it assumes a posix ish environment it does not work on Windows. Nix reportedly works on Windows under Cygwin but I'm not sure how to get it working properly. 6 | 7 | Most of the examples use Nix, some build manually and some do not really use the ffibuild system but are there for completeness and use in [goluwa](https://gitlab.com/CapsAdmin/goluwa). 8 | 9 | 10 | ## simple example: 11 | 12 | ```lua 13 | local code = "local CLIB = ffi.load('purple')\n" 14 | code = code .. "local library = {}\n" 15 | 16 | local header = ffibuild.ProcessSourceFileGCC([[ 17 | #define PURPLE_PLUGINS 18 | #include 19 | ]], "$(pkg-config purple --cflags)") 20 | 21 | local meta_data = ffibuild.GetMetaData(header) 22 | 23 | for func_name, func_type in pairs(meta_data.functions) do 24 | local friendly_name = ffibuild.ChangeCase(func_name, "foo_bar", "fooBar") 25 | code = code .. "library." .. friendly_name .. " = " .. ffibuild.BuildLuaFunction(func_name, func_type) .. "\n" 26 | end 27 | 28 | code = code .. "return library\n" 29 | ``` 30 | 31 | This creates a bunch of globals from this_casing to thisCasing based header input. 32 | 33 | 34 | 35 | ## ffi.GetMetaData(header) 36 | ffi.GetMetaData returns a table structured like so 37 | 38 | ```lua 39 | { 40 | functions = {[function], ...}, 41 | structs = {struct _PurpleAccount = [struct], struct _PurpleBuddy = [struct]}, 42 | unions = {union _PurpleAccount = [union], ...}, 43 | typedefs = {gboolean = [type], gint = [type], ...}, 44 | variables = {[variable], ...}, 45 | enums = {[enums], [enums], [enums]}, 46 | global_enums = {[enums], [enums], [enums]}, 47 | } = ffibuild.GetMetaData(header) 48 | ``` 49 | 50 | Where [???] represents a type object. 51 | 52 | the returned meta_data also has some functions. 53 | 54 | ```lua 55 | meta_data:GetStructTypes(pattern) -- returns a table with all structs whose tag matches the pattern 56 | meta_data:FindFunctions(pattern, from, to) -- returns a table with all functions whose name matches the pattern. from and to is just a shortcut for ffibuild.ChangeCase(str, from, to) 57 | meta_data:GetFunctionsStartingWithType(type) -- returns a table with all functions that starts with the type (useful for object functions) 58 | meta_data:BuildMinimalHeader(check_function, check_enum, keep_structs) -- returns a minimal header where check function and enum are used as filters and keep_structs make it so structs are not empty (which might not be useful) 59 | meta_data:BuildFunctions(pattern) -- this builds a table of functions and somewhat automates the first example in this readme 60 | meta_data:BuildEnums(pattern) -- this builds a table of enums. usually in examples enums are built so they can be accessed like library.e.FOO 61 | ``` 62 | 63 | 64 | ## types 65 | ```lua 66 | -- all functions that take meta_data will attempt to get the most primitive type or declaration 67 | string = type:GetDeclaration(meta_data) -- Gets the declaration for the type such as "const char *", "void (*)(int, char)", "enums {FOO=1,BAR=2}", etc 68 | string = type:GetBasicType(meta_data) -- Gets the basic type such as if type:GetDeclaration() would return "const char *" type:GetbasicType() would return "char" 69 | [type] = type:GetPrimitive(meta_data) -- Attempts to get the primitive type. 70 | ``` 71 | 72 | ## functions 73 | ```lua 74 | func_type:GetDeclaration(as_callback) -- gets the function declaration or as a callback if requested. A function cold also be a callback intitially and so GetDeclaration would return that by default. 75 | 76 | if func_type.arguments then 77 | for arg_pos, type in ipairs(func_type.arguments) do 78 | -- see type section above 79 | type.name -- the name of this argument if any 80 | end 81 | end 82 | 83 | func_type.return_type -- the return argument type 84 | ``` 85 | 86 | ## trimming the header and evaluating types 87 | 88 | In the first example you would get glib functions exported as well since purple uses them internally. This is generally not wanted but you can use `meta_data:BuildMinimalHeader(check_function, check_enum, keep_structs)` where check_function would be a function to find c functions. Based on the functions you need it will return a stripped down header based on the function arguments. 89 | 90 | ```lua 91 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^purple_") end, function(name) return name:find("PURPLE_") end, true) 92 | ``` 93 | 94 | This would return a header with all functions that start with `purple_` and the required structs, unions and enums based on what those functions need. The check enum function will just remove any global or typedef enum that don't start with `PURPLE_` 95 | 96 | ## caveats: 97 | 98 | Sometimes you need to hack the meta data so ffi.cdef can understand it. For instance: 99 | 100 | * #define enums can sometimes be problematic, however there are tools to deal with this 101 | * sometimes a library can define a function that uses problematic types. 102 | 103 | The examples provided should explain some of these workarounds to get an idea of what you need to do. Usually the easy way is to make the problematic type `void *` 104 | 105 | ## todo 106 | * Get this and Nix working in msys2 somehow. 107 | * Provide nix expressions for lesser known libraries (VTFLib, graphene, etc) 108 | * Don't strip out pragma pack and other compiler specific things 109 | * Make struct to table functions 110 | * Have a way to make anonymous definitions using typeof and parameterized types 111 | * add a way to prefix types for "namespaces" to avoid conflicting libraries 112 | -------------------------------------------------------------------------------- /SDL2/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | 5 | local header = ffibuild.NixBuild({ 6 | package_name = "SDL2", 7 | custom = [[ 8 | SDL2 = pkgs.SDL2.override { 9 | pulseaudioSupport = false; 10 | waylandSupport = false; 11 | x11Support = false; 12 | alsaSupport = fasle; 13 | }; 14 | 15 | #SDL2 = SDL2.overrideAttrs (old: { 16 | # configureFlags = old.configureFlags ++ [ "--disable-audio" "--disable-render" "--disable-haptic" "--disable-filesystem" "--disable-file" ]; 17 | #}); 18 | 19 | ]], 20 | src = [[ 21 | typedef enum { 22 | SDL_INIT_TIMER = 0x00000001, 23 | SDL_INIT_AUDIO = 0x00000010, 24 | SDL_INIT_VIDEO = 0x00000020, 25 | SDL_INIT_JOYSTICK = 0x00000200, 26 | SDL_INIT_HAPTIC = 0x00001000, 27 | SDL_INIT_GAMECONTROLLER = 0x00002000, 28 | SDL_INIT_EVENTS = 0x00004000, 29 | SDL_INIT_NOPARACHUTE = 0x00100000, 30 | SDL_INIT_EVERYTHING = SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER, 31 | 32 | SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000, 33 | SDL_WINDOWPOS_UNDEFINED_DISPLAY = SDL_WINDOWPOS_UNDEFINED_MASK, 34 | SDL_WINDOWPOS_UNDEFINED = SDL_WINDOWPOS_UNDEFINED_DISPLAY, 35 | SDL_WINDOWPOS_CENTERED_MASK = 0x2FFF0000, 36 | SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK 37 | } SDL_grrrrrr; 38 | 39 | typedef struct wl_display {} wl_display; 40 | typedef struct wl_surface {} wl_surface; 41 | typedef struct wl_shell_surface {} wl_shell_surface; 42 | 43 | #include "SDL2/SDL_video.h" 44 | #include "SDL2/SDL_shape.h" 45 | #include "SDL2/SDL.h" 46 | #include "SDL2/SDL_syswm.h" 47 | 48 | ]]}) 49 | 50 | --[==[ 51 | ffibuild.ManualBuild( 52 | "SDL2", 53 | "https://hg.libsdl.org/SDL", 54 | "./autogen.sh && mkdir build && cd build && ../configure --disable-audio --disable-render --disable-haptic --disable-filesystem --disable-file && make && cd ../" 55 | ) 56 | 57 | local header = ffibuild.ProcessSourceFileGCC([[ 58 | typedef enum { 59 | SDL_INIT_TIMER = 0x00000001, 60 | SDL_INIT_AUDIO = 0x00000010, 61 | SDL_INIT_VIDEO = 0x00000020, 62 | SDL_INIT_JOYSTICK = 0x00000200, 63 | SDL_INIT_HAPTIC = 0x00001000, 64 | SDL_INIT_GAMECONTROLLER = 0x00002000, 65 | SDL_INIT_EVENTS = 0x00004000, 66 | SDL_INIT_NOPARACHUTE = 0x00100000, 67 | SDL_INIT_EVERYTHING = SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER, 68 | 69 | SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000, 70 | SDL_WINDOWPOS_UNDEFINED_DISPLAY = SDL_WINDOWPOS_UNDEFINED_MASK, 71 | SDL_WINDOWPOS_UNDEFINED = SDL_WINDOWPOS_UNDEFINED_DISPLAY, 72 | SDL_WINDOWPOS_CENTERED_MASK = 0x2FFF0000, 73 | SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK 74 | } SDL_grrrrrr; 75 | 76 | #include "SDL_video.h" 77 | #include "SDL_shape.h" 78 | #include "SDL.h" 79 | #include "SDL_syswm.h" 80 | 81 | ]], "-I./repo/include") 82 | ]==] 83 | header = "struct SDL_BlitMap {};\n" .. header 84 | 85 | local meta_data = ffibuild.GetMetaData(header) 86 | meta_data.functions.SDL_main = nil 87 | 88 | meta_data.structs["struct SDL_WindowShapeMode"] = nil 89 | meta_data.functions.SDL_SetWindowShape.arguments[3] = ffibuild.CreateType("type", "void *") 90 | meta_data.functions.SDL_GetShapedWindowMode.arguments[2] = ffibuild.CreateType("type", "void *") 91 | 92 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^SDL_") end, function(name) return name:find("^SDL_") or name:find("^KMOD_") end, true, true) 93 | 94 | header = header:gsub("struct VkSurfaceKHR_T {};\n", "") 95 | header = header:gsub("struct VkInstance_T {};\n", "") 96 | 97 | header = header:gsub("struct VkInstance_T", "void") 98 | header = header:gsub("struct VkSurfaceKHR_T", "void") 99 | 100 | local lua = ffibuild.StartLibrary(header) 101 | 102 | lua = lua .. "library = " .. meta_data:BuildFunctions("^SDL_(.+)") 103 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^SDL_(.+)", {"./include/SDL2/SDL_hints.h"}, "SDL_") 104 | 105 | lua = lua .. [[ 106 | function library.CreateVulkanSurface(window, instance) 107 | local box = ffi.new("struct VkSurfaceKHR_T * [1]") 108 | 109 | if library.Vulkan_CreateSurface(window, instance, ffi.cast("void**", box)) == nil then 110 | return nil, ffi.string(library.GetError()) 111 | end 112 | 113 | return box[0] 114 | end 115 | 116 | function library.GetRequiredInstanceExtensions(wnd, extra) 117 | local count = ffi.new("uint32_t[1]") 118 | 119 | if library.Vulkan_GetInstanceExtensions(wnd, count, nil) == 0 then 120 | return nil, ffi.string(library.GetError()) 121 | end 122 | 123 | local array = ffi.new("const char *[?]", count[0]) 124 | 125 | if library.Vulkan_GetInstanceExtensions(wnd, count, array) == 0 then 126 | return nil, ffi.string(library.GetError()) 127 | end 128 | 129 | local out = {} 130 | for i = 0, count[0] - 1 do 131 | table.insert(out, ffi.string(array[i])) 132 | end 133 | 134 | if extra then 135 | for i,v in ipairs(extra) do 136 | table.insert(out, v) 137 | end 138 | end 139 | 140 | return out 141 | end 142 | ]] 143 | 144 | ffibuild.EndLibrary(lua, header) 145 | -------------------------------------------------------------------------------- /SDL2/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /VTFLib/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.checkcmds("cmake", "git", "make") 5 | 6 | ffibuild.ManualBuild( 7 | "VTFLib", 8 | "https://github.com/CapsAdmin/VTFLib.git", 9 | "cmake . -DUSE_LIBTXC_DXTN=0 && make" 10 | ) 11 | 12 | local header = ffibuild.ProcessSourceFileGCC([[ 13 | typedef struct tagSVTFImageFormatInfo {} SVTFImageFormatInfo; 14 | #include "VTFLib.h" 15 | #include "VTFWrapper.h" 16 | #include "VMTWrapper.h" 17 | ]], "-I./repo/src") 18 | 19 | 20 | local meta_data = ffibuild.GetMetaData(header) 21 | 22 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^vl") end, function(name) return true end, true, true) 23 | local lua = ffibuild.StartLibrary(header) 24 | 25 | lua = lua .. "library = " .. meta_data:BuildFunctions("^vl(.+)") 26 | lua = lua .. "library.e = " .. meta_data:BuildEnums(nil,nil,nil,"^enum tagVTF") 27 | 28 | lua = lua .. [[ 29 | 30 | 31 | local function float(high, low) 32 | local b = low 33 | local sign = 1 34 | if b >= 128 then 35 | sign = -1 36 | b = b - 128 37 | end 38 | local exponent = bit.rshift(b, 2) - 15 39 | local mantissa = bit.band(b, 3) / 4 40 | 41 | b = high 42 | mantissa = mantissa + b / 4 / 256 43 | 44 | if mantissa == 0 and exponent == -15 then 45 | return 0 46 | else 47 | return (mantissa + 1) * math.pow(2, exponent) * sign 48 | end 49 | end 50 | 51 | local function half_buffer_to_float_buffer(length, buffer) 52 | local out = ffi.new("float[?]", length) 53 | local i2 = 0 54 | for i = 1, length * 2, 2 do 55 | i = i -1 56 | out[i2] = float(buffer[i + 0], buffer[i + 1]) 57 | i2 = i2 + 1 58 | end 59 | return ffi.cast("uint8_t *", out) 60 | end 61 | 62 | local function cleanup(vtf_material, vtf_image) 63 | library.ImageDestroy() 64 | library.MaterialDestroy() 65 | library.DeleteMaterial(vtf_material[0]) 66 | library.DeleteImage(vtf_image[0]) 67 | end 68 | 69 | local function get_error() 70 | return ffi.string(library.GetLastError()) 71 | end 72 | 73 | function library.LoadImage(data, path_hint) 74 | local vtf_image = ffi.new("unsigned int[1]") 75 | if library.CreateImage(vtf_image) == 0 then return false, "failed to create image: " .. get_error() end 76 | if library.BindImage(vtf_image[0]) == 0 then return false, "failed to bind image: " .. get_error() end 77 | 78 | -- dummy material 79 | local vtf_material = ffi.new("unsigned int[1]") 80 | if library.CreateMaterial(vtf_material) == 0 then return false, "failed to create material: " .. get_error() end 81 | if library.BindMaterial(vtf_material[0]) == 0 then return false, "failed to bind material: " .. get_error() end 82 | 83 | if library.ImageLoadLump(ffi.cast("void *", data), #data, 0) == 0 then 84 | return nil, "unknown format" 85 | end 86 | 87 | local width = library.ImageGetWidth() 88 | local height = library.ImageGetHeight() 89 | local internal_format = library.ImageGetFormat() 90 | local conversion_format = internal_format 91 | local buffer 92 | 93 | do 94 | local internal_buffer = library.ImageGetData(0, 0, 0, 0) 95 | local info = library.ImageGetImageFormatInfo(internal_format) 96 | 97 | if info.bIsCompressed == 1 then 98 | if info.uiAlphaBitsPerPixel > 0 then 99 | conversion_format = library.e.IMAGE_FORMAT_RGBA8888 100 | else 101 | conversion_format = library.e.IMAGE_FORMAT_RGB888 102 | end 103 | end 104 | 105 | local size = library.ImageComputeImageSize(width, height, 1, 1, conversion_format) 106 | buffer = ffi.new("uint8_t[?]", size) 107 | 108 | if library.ImageConvert(internal_buffer, buffer, width, height, internal_format, conversion_format) == 0 then 109 | cleanup(vtf_material, vtf_image) 110 | return false, "conversion from " .. tostring(internal_format) .. " to " .. tostring(conversion_format) .. " failed: " .. get_error() 111 | end 112 | end 113 | 114 | local format = "rgba" 115 | local type = "unsigned_byte" 116 | 117 | if conversion_format == library.e.IMAGE_FORMAT_RGBA8888 then 118 | format = "rgba" 119 | elseif conversion_format == library.e.IMAGE_FORMAT_RGB888 then 120 | format = "rgb" 121 | elseif conversion_format == library.e.IMAGE_FORMAT_BGRA8888 then 122 | if path_hint and path_hint:find(".+/[^/]-hdr[^/]-%.vtf") then 123 | format = "bgr" 124 | type = "float" 125 | 126 | local new = ffi.new("float[?][3]", width * height) 127 | local i2 = 0 128 | for i = 1, (width * height) * 4, 4 do 129 | i = i - 1 130 | local r = buffer[i + 0] 131 | local g = buffer[i + 1] 132 | local b = buffer[i + 2] 133 | local a = buffer[i + 3] 134 | 135 | r = (r * (a * 16)) / 262144 136 | g = (g * (a * 16)) / 262144 137 | b = (b * (a * 16)) / 262144 138 | 139 | new[i2][0] = r 140 | new[i2][1] = g 141 | new[i2][2] = b 142 | i2 = i2 + 1 143 | end 144 | buffer = new 145 | else 146 | format = "bgra" 147 | end 148 | elseif conversion_format == library.e.IMAGE_FORMAT_BGR888 then 149 | format = "bgr" 150 | elseif conversion_format == library.e.IMAGE_FORMAT_RGBA32323232F then 151 | format = "rgba" 152 | type = "float" 153 | elseif conversion_format == library.e.IMAGE_FORMAT_RGB323232F then 154 | format = "rgb" 155 | type = "float" 156 | elseif conversion_format == library.e.IMAGE_FORMAT_RGBA16161616F then 157 | format = "rgba" 158 | type = "float" 159 | buffer = half_buffer_to_float_buffer((width * height) * 4, buffer) 160 | elseif conversion_format == library.e.IMAGE_FORMAT_RGB161616F then 161 | format = "rgb" 162 | type = "float" 163 | buffer = half_buffer_to_float_buffer((width * height) * 4, buffer) 164 | else 165 | wlog("unhandled image format: %s", conversion_format) 166 | end 167 | 168 | cleanup(vtf_material, vtf_image) 169 | 170 | return { 171 | buffer = buffer, 172 | width = width, 173 | height = height, 174 | format = format, 175 | type = type, 176 | } 177 | end 178 | ]] 179 | 180 | ffibuild.EndLibrary(lua, header) 181 | -------------------------------------------------------------------------------- /VTFLib/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /assimp/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.setenv("NIXPKGS_ALLOW_BROKEN", "1") 5 | 6 | local header = ffibuild.NixBuild({ 7 | package_name = "assimp", 8 | src = [[ 9 | #include "assimp/types.h" 10 | #include "assimp/metadata.h" 11 | #include "assimp/ai_assert.h" 12 | #include "assimp/cexport.h" 13 | #include "assimp/color4.h" 14 | #include "assimp/config.h" 15 | #include "assimp/matrix4x4.h" 16 | #include "assimp/postprocess.h" 17 | #include "assimp/vector3.h" 18 | #include "assimp/anim.h" 19 | #include "assimp/cfileio.h" 20 | #include "assimp/importerdesc.h" 21 | #include "assimp/matrix3x3.h" 22 | #include "assimp/scene.h" 23 | #include "assimp/vector2.h" 24 | #include "assimp/camera.h" 25 | #include "assimp/cimport.h" 26 | #include "assimp/defs.h" 27 | #include "assimp/light.h" 28 | #include "assimp/material.h" 29 | #include "assimp/mesh.h" 30 | #include "assimp/quaternion.h" 31 | #include "assimp/texture.h" 32 | #include "assimp/version.h" 33 | 34 | 35 | #undef aiProcess_ConvertToLeftHanded 36 | #undef aiProcessPreset_TargetRealtime_Fast 37 | #undef aiProcessPreset_TargetRealtime_Quality 38 | #undef aiProcessPreset_TargetRealtime_MaxQuality 39 | 40 | typedef enum { 41 | aiProcess_ConvertToLeftHanded = 42 | aiProcess_MakeLeftHanded | 43 | aiProcess_FlipUVs | 44 | aiProcess_FlipWindingOrder | 45 | 0, 46 | 47 | aiProcessPreset_TargetRealtime_Fast = 48 | aiProcess_CalcTangentSpace | 49 | aiProcess_GenNormals | 50 | aiProcess_JoinIdenticalVertices | 51 | aiProcess_Triangulate | 52 | aiProcess_GenUVCoords | 53 | aiProcess_SortByPType | 54 | 0, 55 | 56 | aiProcessPreset_TargetRealtime_Quality = 57 | aiProcess_CalcTangentSpace | 58 | aiProcess_GenSmoothNormals | 59 | aiProcess_JoinIdenticalVertices | 60 | aiProcess_ImproveCacheLocality | 61 | aiProcess_LimitBoneWeights | 62 | aiProcess_RemoveRedundantMaterials | 63 | aiProcess_SplitLargeMeshes | 64 | aiProcess_Triangulate | 65 | aiProcess_GenUVCoords | 66 | aiProcess_SortByPType | 67 | aiProcess_FindDegenerates | 68 | aiProcess_FindInvalidData | 69 | 0, 70 | 71 | aiProcessPreset_TargetRealtime_MaxQuality = 72 | aiProcessPreset_TargetRealtime_Quality | 73 | aiProcess_FindInstances | 74 | aiProcess_ValidateDataStructure | 75 | aiProcess_OptimizeMeshes | 76 | 0 77 | } aiGrrr; 78 | 79 | typedef struct aiFile aiFile; 80 | 81 | ]]}) 82 | 83 | header = header:gsub("(%s)AI_", "%1ai") 84 | 85 | local meta_data = ffibuild.GetMetaData(header) 86 | meta_data.functions.aiGetImporterDesc = nil 87 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^ai") end, function(name) return name:find("^ai") end, true, true) 88 | local lua = ffibuild.StartLibrary(header) 89 | 90 | lua = lua .. "library = " .. meta_data:BuildFunctions("^ai(.+)") 91 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^ai.-_(%u.+)") 92 | 93 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /assimp/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /bgfx/.gitignore: -------------------------------------------------------------------------------- 1 | bx/ 2 | bimg/ 3 | -------------------------------------------------------------------------------- /bgfx/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.checkcmds("meson", "ninja", "git") 5 | 6 | os.execute("git clone https://github.com/bkaradzic/bx --depth 1") 7 | os.execute("git clone https://github.com/bkaradzic/bimg --depth 1") 8 | 9 | ffibuild.ManualBuild( 10 | "bgfx", 11 | "https://github.com/bkaradzic/bgfx.git", 12 | "make linux-release64" 13 | ) 14 | 15 | local header = ffibuild.ProcessSourceFileGCC([[ 16 | #include "bgfx/c99/bgfx.h" 17 | ]], "-I./repo/include/ -I./bx/include/") 18 | 19 | local meta_data = ffibuild.GetMetaData(header) 20 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^bgfx_") end, function(name) return name:find("^BGFX_") end, true, true) 21 | local lua = ffibuild.StartLibrary(header) 22 | 23 | lua = lua .. "library = " .. meta_data:BuildFunctions("^bgfx_(.+)", "foo_bar", "FooBar") 24 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^BGFX_(.+)", "./repo/include/bgfx/defines.h", "BGFX_") 25 | 26 | ffibuild.EndLibrary(lua, header) 27 | -------------------------------------------------------------------------------- /bgfx/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /bullet/build.lua: -------------------------------------------------------------------------------- 1 | if render then 2 | os.execute("cd ../ffibuild/bullet/ && bash make.sh") 3 | os.execute("cp -f ../ffibuild/bullet/bullet.lua ./bullet.lua") 4 | return 5 | end 6 | 7 | package.path = package.path .. ";../?.lua" 8 | local ffibuild = require("ffibuild") 9 | 10 | --ffibuild.Clone("https://github.com/bulletphysics/bullet3.git", "repo/bullet") 11 | --ffibuild.Clone("https://github.com/AndresTraks/BulletSharpPInvoke.git", "repo/libbulletc") 12 | 13 | --os.execute("mkdir -p repo/libbulletc/libbulletc/build") 14 | --os.execute("cd repo/libbulletc/libbulletc/build && cmake .. && make") 15 | --os.execute("cp repo/libbulletc/libbulletc/build/libbulletc.so .") 16 | 17 | ffibuild.lib_name = "bullet" 18 | 19 | local header = ffibuild.ProcessSourceFileGCC([[ 20 | #include "bulletc.h" 21 | 22 | ]], "-I./repo/libbulletc/libbulletc/src/") 23 | 24 | io.writefile("lol.c", header) 25 | 26 | local meta_data = ffibuild.GetMetaData(header) 27 | 28 | local objects = {} 29 | 30 | for key, tbl in pairs(meta_data.functions) do 31 | if key:sub(1, 2) == "bt" then 32 | local t = key:match("^(.+)_[^_]+$") 33 | if t then 34 | objects[t] = objects[t] or {ctors = {}, functions = {}} 35 | else 36 | -- print(key) 37 | end 38 | else 39 | -- print(key) 40 | end 41 | end 42 | 43 | do 44 | local temp = {} 45 | for k,v in pairs(objects) do 46 | v.name = k 47 | table.insert(temp, v) 48 | end 49 | table.sort(temp, function(a, b) return #a.name > #b.name end) 50 | 51 | objects = temp 52 | end 53 | 54 | local done = {} 55 | 56 | for _, info in ipairs(objects) do 57 | for key, tbl in pairs(meta_data.functions) do 58 | if not done[key] and key:sub(1, #info.name) == info.name then 59 | if key:find("_new", nil, true) then 60 | table.insert(info.ctors, key) 61 | done[key] = true 62 | else 63 | local friendly = key:sub(#info.name+2) 64 | if friendly == "" then friendly = key end 65 | table.insert(info.functions, {func = key, friendly = ffibuild.ChangeCase(friendly, "fooBar", "FooBar")}) 66 | done[key] = true 67 | end 68 | end 69 | end 70 | end 71 | 72 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^bt%u") end, function(name) return name:find("^bt%u") end, true, true) 73 | 74 | local lua = ffibuild.StartLibrary(header) 75 | 76 | local ffi = require("ffi") 77 | local clib = ffi.load("./libbullet.so") 78 | ffi.cdef(header) 79 | lua = lua .. "library = " .. meta_data:BuildFunctions("^bt(%u.+)", nil, nil, nil, function(name) 80 | local ok, err = pcall(function() return clib[name] end) 81 | if not pcall(function() return clib[name] end) then 82 | return false 83 | end 84 | end) 85 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^bt(%u.+)") 86 | 87 | lua = lua .. "library.metatables = {}\n" 88 | 89 | local inheritance = { 90 | btDiscreteDynamicsWorld = "btDynamicsWorld", 91 | btDynamicsWorld = "btCollisionWorld", 92 | 93 | btRigidBody = "btCollisionObject", 94 | 95 | btBoxShape = "btConvexInternalShape", 96 | btSphereShape = "btConvexInternalShape", 97 | btConvexInternalShape = "btConvexShape", 98 | btConvexShape = "btCollisionShape", 99 | } 100 | 101 | do 102 | collectgarbage() 103 | 104 | for _, info in ipairs(objects) do 105 | local s = "" 106 | 107 | s = s .. "do -- " .. info.name .. "\n" 108 | s = s .. "\tlocal META = {}\n" 109 | s = s .. "\tlibrary.metatables."..info.name.." = META\n" 110 | 111 | if inheritance[info.name] then 112 | s = s .. "\tfunction META:__index(k)\n" 113 | 114 | s = s .. "\t\tlocal v\n\n" 115 | 116 | s = s .. "\t\tv = META[k]\n" 117 | s = s .. "\t\tif v ~= nil then\n" 118 | s = s .. "\t\t\treturn v\n" 119 | s = s .. "\t\tend\n" 120 | 121 | s = s .. "\t\tv = library.metatables."..inheritance[info.name]..".__index(self, k)\n" 122 | s = s .. "\t\tif v ~= nil then\n" 123 | s = s .. "\t\t\treturn v\n" 124 | s = s .. "\t\tend\n" 125 | 126 | s = s .. "\tend\n" 127 | else 128 | s = s .. "\tMETA.__index = function(s, k) return META[k] end\n" 129 | end 130 | 131 | for i, func_name in ipairs(info.ctors) do 132 | if i == 1 then i = "" end 133 | s = s .. "\tfunction library.Create" .. info.name:sub(3) .. i .. "(...)\n" 134 | s = s .. "\t\tlocal self = setmetatable({}, META)\n" 135 | s = s .. "\t\tself.ptr = CLIB."..func_name.."(...)\n" 136 | s = s .. "\t\treturn self\n" 137 | s = s .. "\tend\n" 138 | end 139 | 140 | for k,v in ipairs(info.functions) do 141 | s = s .. "\tfunction META:" .. v.friendly .. "(...)\n" 142 | s = s .. "\t\treturn CLIB." .. v.func .. "(self.ptr, ...)\n" 143 | s = s .. "\tend\n" 144 | end 145 | 146 | s = s .. "end\n" 147 | 148 | lua = lua .. s 149 | end 150 | end 151 | 152 | ffibuild.EndLibrary(lua, header) 153 | -------------------------------------------------------------------------------- /bullet/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /curses/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | ffibuild.NixBuild({ 5 | package_name = "ncurses", 6 | src = "", 7 | }) -------------------------------------------------------------------------------- /curses/curses.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | 3 | local header = [[ 4 | typedef void * FILE; 5 | typedef uint64_t chtype; 6 | typedef chtype attr_t; 7 | typedef struct 8 | { 9 | int x; 10 | int y; 11 | short button[3]; 12 | int changes; 13 | short xbutton[6]; 14 | } MOUSE_STATUS; 15 | typedef unsigned long mmask_t; 16 | typedef struct 17 | { 18 | short id; 19 | int x, y, z; 20 | mmask_t bstate; 21 | } MEVENT; 22 | typedef struct _win 23 | { 24 | int _cury; 25 | int _curx; 26 | int _maxy; 27 | int _maxx; 28 | int _begy; 29 | int _begx; 30 | int _flags; 31 | chtype _attrs; 32 | chtype _bkgd; 33 | bool _clear; 34 | bool _leaveit; 35 | bool _scroll; 36 | bool _nodelay; 37 | bool _immed; 38 | bool _sync; 39 | bool _use_keypad; 40 | chtype **_y; 41 | int *_firstch; 42 | int *_lastch; 43 | int _tmarg; 44 | int _bmarg; 45 | int _delayms; 46 | int _parx, _pary; 47 | struct _win *_parent; 48 | } WINDOW; 49 | typedef struct 50 | { 51 | bool alive; 52 | bool autocr; 53 | bool cbreak; 54 | bool echo; 55 | bool raw_inp; 56 | bool raw_out; 57 | bool audible; 58 | bool mono; 59 | bool resized; 60 | bool orig_attr; 61 | short orig_fore; 62 | short orig_back; 63 | int cursrow; 64 | int curscol; 65 | int visibility; 66 | int orig_cursor; 67 | int lines; 68 | int cols; 69 | unsigned long _trap_mbe; 70 | unsigned long _map_mbe_to_key; 71 | int mouse_wait; 72 | int slklines; 73 | WINDOW *slk_winptr; 74 | int linesrippedoff; 75 | int linesrippedoffontop; 76 | int delaytenths; 77 | bool _preserve; 78 | int _restore; 79 | bool save_key_modifiers; 80 | bool return_key_modifiers; 81 | bool key_code; 82 | short line_color; 83 | } SCREEN; 84 | extern int LINES; 85 | extern int COLS; 86 | extern WINDOW *stdscr; 87 | extern WINDOW *curscr; 88 | extern SCREEN *SP; 89 | extern MOUSE_STATUS Mouse_status; 90 | extern int COLORS; 91 | extern int COLOR_PAIRS; 92 | extern int TABSIZE; 93 | extern chtype acs_map[]; 94 | extern char ttytype[]; 95 | int addch(const chtype); 96 | int addchnstr(const chtype *, int); 97 | int addchstr(const chtype *); 98 | int addnstr(const char *, int); 99 | int addstr(const char *); 100 | int attroff(chtype); 101 | int attron(chtype); 102 | int attrset(chtype); 103 | int attr_get(attr_t *, short *, void *); 104 | int attr_off(attr_t, void *); 105 | int attr_on(attr_t, void *); 106 | int attr_set(attr_t, short, void *); 107 | int baudrate(void); 108 | int beep(void); 109 | int bkgd(chtype); 110 | void bkgdset(chtype); 111 | int border(chtype, chtype, chtype, chtype, chtype, chtype, chtype, chtype); 112 | int box(WINDOW *, chtype, chtype); 113 | bool can_change_color(void); 114 | int cbreak(void); 115 | int chgat(int, attr_t, short, const void *); 116 | int clearok(WINDOW *, bool); 117 | int clear(void); 118 | int clrtobot(void); 119 | int clrtoeol(void); 120 | int color_content(short, short *, short *, short *); 121 | int color_set(short, void *); 122 | int copywin(const WINDOW *, WINDOW *, int, int, int, int, int, int, int); 123 | int curs_set(int); 124 | int def_prog_mode(void); 125 | int def_shell_mode(void); 126 | int delay_output(int); 127 | int delch(void); 128 | int deleteln(void); 129 | void delscreen(SCREEN *); 130 | int delwin(WINDOW *); 131 | WINDOW *derwin(WINDOW *, int, int, int, int); 132 | int doupdate(void); 133 | WINDOW *dupwin(WINDOW *); 134 | int echochar(const chtype); 135 | int echo(void); 136 | int endwin(void); 137 | char erasechar(void); 138 | int erase(void); 139 | void filter(void); 140 | int flash(void); 141 | int flushinp(void); 142 | chtype getbkgd(WINDOW *); 143 | int getnstr(char *, int); 144 | int getstr(char *); 145 | WINDOW *getwin(FILE *); 146 | int halfdelay(int); 147 | bool has_colors(void); 148 | bool has_ic(void); 149 | bool has_il(void); 150 | int hline(chtype, int); 151 | void idcok(WINDOW *, bool); 152 | int idlok(WINDOW *, bool); 153 | void immedok(WINDOW *, bool); 154 | int inchnstr(chtype *, int); 155 | int inchstr(chtype *); 156 | chtype inch(void); 157 | int init_color(short, short, short, short); 158 | int init_pair(short, short, short); 159 | WINDOW *initscr(void); 160 | int innstr(char *, int); 161 | int insch(chtype); 162 | int insdelln(int); 163 | int insertln(void); 164 | int insnstr(const char *, int); 165 | int insstr(const char *); 166 | int instr(char *); 167 | int intrflush(WINDOW *, bool); 168 | bool isendwin(void); 169 | bool is_linetouched(WINDOW *, int); 170 | bool is_wintouched(WINDOW *); 171 | char *keyname(int); 172 | int keypad(WINDOW *, bool); 173 | char killchar(void); 174 | int leaveok(WINDOW *, bool); 175 | char *longname(void); 176 | int meta(WINDOW *, bool); 177 | int move(int, int); 178 | int mvaddch(int, int, const chtype); 179 | int mvaddchnstr(int, int, const chtype *, int); 180 | int mvaddchstr(int, int, const chtype *); 181 | int mvaddnstr(int, int, const char *, int); 182 | int mvaddstr(int, int, const char *); 183 | int mvchgat(int, int, int, attr_t, short, const void *); 184 | int mvcur(int, int, int, int); 185 | int mvdelch(int, int); 186 | int mvderwin(WINDOW *, int, int); 187 | int mvgetch(int, int); 188 | int mvgetnstr(int, int, char *, int); 189 | int mvgetstr(int, int, char *); 190 | int mvhline(int, int, chtype, int); 191 | chtype mvinch(int, int); 192 | int mvinchnstr(int, int, chtype *, int); 193 | int mvinchstr(int, int, chtype *); 194 | int mvinnstr(int, int, char *, int); 195 | int mvinsch(int, int, chtype); 196 | int mvinsnstr(int, int, const char *, int); 197 | int mvinsstr(int, int, const char *); 198 | int mvinstr(int, int, char *); 199 | int mvprintw(int, int, const char *, ...); 200 | int mvscanw(int, int, const char *, ...); 201 | int mvvline(int, int, chtype, int); 202 | int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); 203 | int mvwaddchstr(WINDOW *, int, int, const chtype *); 204 | int mvwaddch(WINDOW *, int, int, const chtype); 205 | int mvwaddnstr(WINDOW *, int, int, const char *, int); 206 | int mvwaddstr(WINDOW *, int, int, const char *); 207 | int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *); 208 | int mvwdelch(WINDOW *, int, int); 209 | int mvwgetch(WINDOW *, int, int); 210 | int mvwgetnstr(WINDOW *, int, int, char *, int); 211 | int mvwgetstr(WINDOW *, int, int, char *); 212 | int mvwhline(WINDOW *, int, int, chtype, int); 213 | int mvwinchnstr(WINDOW *, int, int, chtype *, int); 214 | int mvwinchstr(WINDOW *, int, int, chtype *); 215 | chtype mvwinch(WINDOW *, int, int); 216 | int mvwinnstr(WINDOW *, int, int, char *, int); 217 | int mvwinsch(WINDOW *, int, int, chtype); 218 | int mvwinsnstr(WINDOW *, int, int, const char *, int); 219 | int mvwinsstr(WINDOW *, int, int, const char *); 220 | int mvwinstr(WINDOW *, int, int, char *); 221 | int mvwin(WINDOW *, int, int); 222 | int mvwprintw(WINDOW *, int, int, const char *, ...); 223 | int mvwscanw(WINDOW *, int, int, const char *, ...); 224 | int mvwvline(WINDOW *, int, int, chtype, int); 225 | int napms(int); 226 | WINDOW *newpad(int, int); 227 | SCREEN *newterm(const char *, FILE *, FILE *); 228 | WINDOW *newwin(int, int, int, int); 229 | int nl(void); 230 | int nocbreak(void); 231 | int nodelay(WINDOW *, bool); 232 | int noecho(void); 233 | int nonl(void); 234 | void noqiflush(void); 235 | int noraw(void); 236 | int notimeout(WINDOW *, bool); 237 | int overlay(const WINDOW *, WINDOW *); 238 | int overwrite(const WINDOW *, WINDOW *); 239 | int pair_content(short, short *, short *); 240 | int pechochar(WINDOW *, chtype); 241 | int pnoutrefresh(WINDOW *, int, int, int, int, int, int); 242 | int prefresh(WINDOW *, int, int, int, int, int, int); 243 | int printw(const char *, ...); 244 | int putwin(WINDOW *, FILE *); 245 | void qiflush(void); 246 | int raw(void); 247 | int redrawwin(WINDOW *); 248 | int refresh(void); 249 | int reset_prog_mode(void); 250 | int reset_shell_mode(void); 251 | int resetty(void); 252 | int ripoffline(int, int (*)(WINDOW *, int)); 253 | int savetty(void); 254 | int scanw(const char *, ...); 255 | int scr_dump(const char *); 256 | int scr_init(const char *); 257 | int scr_restore(const char *); 258 | int scr_set(const char *); 259 | int scrl(int); 260 | int scroll(WINDOW *); 261 | int scrollok(WINDOW *, bool); 262 | SCREEN *set_term(SCREEN *); 263 | int setscrreg(int, int); 264 | int slk_attroff(const chtype); 265 | int slk_attr_off(const attr_t, void *); 266 | int slk_attron(const chtype); 267 | int slk_attr_on(const attr_t, void *); 268 | int slk_attrset(const chtype); 269 | int slk_attr_set(const attr_t, short, void *); 270 | int slk_clear(void); 271 | int slk_color(short); 272 | int slk_init(int); 273 | char *slk_label(int); 274 | int slk_noutrefresh(void); 275 | int slk_refresh(void); 276 | int slk_restore(void); 277 | int slk_set(int, const char *, int); 278 | int slk_touch(void); 279 | int standend(void); 280 | int standout(void); 281 | int start_color(void); 282 | WINDOW *subpad(WINDOW *, int, int, int, int); 283 | WINDOW *subwin(WINDOW *, int, int, int, int); 284 | int syncok(WINDOW *, bool); 285 | chtype termattrs(void); 286 | attr_t term_attrs(void); 287 | char *termname(void); 288 | void timeout(int); 289 | int touchline(WINDOW *, int, int); 290 | int touchwin(WINDOW *); 291 | int typeahead(int); 292 | int untouchwin(WINDOW *); 293 | void use_env(bool); 294 | int vidattr(chtype); 295 | int vid_attr(attr_t, short, void *); 296 | int vidputs(chtype, int (*)(int)); 297 | int vid_puts(attr_t, short, void *, int (*)(int)); 298 | int vline(chtype, int); 299 | int vw_printw(WINDOW *, const char *, va_list); 300 | int vwprintw(WINDOW *, const char *, va_list); 301 | int vw_scanw(WINDOW *, const char *, va_list); 302 | int vwscanw(WINDOW *, const char *, va_list); 303 | int waddchnstr(WINDOW *, const chtype *, int); 304 | int waddchstr(WINDOW *, const chtype *); 305 | int waddch(WINDOW *, const chtype); 306 | int waddnstr(WINDOW *, const char *, int); 307 | int waddstr(WINDOW *, const char *); 308 | int wattroff(WINDOW *, chtype); 309 | int wattron(WINDOW *, chtype); 310 | int wattrset(WINDOW *, chtype); 311 | int wattr_get(WINDOW *, attr_t *, short *, void *); 312 | int wattr_off(WINDOW *, attr_t, void *); 313 | int wattr_on(WINDOW *, attr_t, void *); 314 | int wattr_set(WINDOW *, attr_t, short, void *); 315 | void wbkgdset(WINDOW *, chtype); 316 | int wbkgd(WINDOW *, chtype); 317 | int wborder(WINDOW *, chtype, chtype, chtype, chtype, 318 | chtype, chtype, chtype, chtype); 319 | int wchgat(WINDOW *, int, attr_t, short, const void *); 320 | int wclear(WINDOW *); 321 | int wclrtobot(WINDOW *); 322 | int wclrtoeol(WINDOW *); 323 | int wcolor_set(WINDOW *, short, void *); 324 | void wcursyncup(WINDOW *); 325 | int wdelch(WINDOW *); 326 | int wdeleteln(WINDOW *); 327 | int wechochar(WINDOW *, const chtype); 328 | int werase(WINDOW *); 329 | int wgetch(WINDOW *); 330 | int ungetch(int); 331 | int wgetnstr(WINDOW *, char *, int); 332 | int wgetstr(WINDOW *, char *); 333 | int whline(WINDOW *, chtype, int); 334 | int winchnstr(WINDOW *, chtype *, int); 335 | int winchstr(WINDOW *, chtype *); 336 | chtype winch(WINDOW *); 337 | int winnstr(WINDOW *, char *, int); 338 | int winsch(WINDOW *, chtype); 339 | int winsdelln(WINDOW *, int); 340 | int winsertln(WINDOW *); 341 | int winsnstr(WINDOW *, const char *, int); 342 | int winsstr(WINDOW *, const char *); 343 | int winstr(WINDOW *, char *); 344 | int wmove(WINDOW *, int, int); 345 | int wnoutrefresh(WINDOW *); 346 | int wprintw(WINDOW *, const char *, ...); 347 | int wredrawln(WINDOW *, int, int); 348 | int wrefresh(WINDOW *); 349 | int wscanw(WINDOW *, const char *, ...); 350 | int wscrl(WINDOW *, int); 351 | int wsetscrreg(WINDOW *, int, int); 352 | int wstandend(WINDOW *); 353 | int wstandout(WINDOW *); 354 | void wsyncdown(WINDOW *); 355 | void wsyncup(WINDOW *); 356 | void wtimeout(WINDOW *, int); 357 | int wtouchln(WINDOW *, int, int, int); 358 | int wvline(WINDOW *, chtype, int); 359 | chtype getattrs(WINDOW *); 360 | int getbegx(WINDOW *); 361 | int getbegy(WINDOW *); 362 | int getmaxx(WINDOW *); 363 | int getmaxy(WINDOW *); 364 | int getparx(WINDOW *); 365 | int getpary(WINDOW *); 366 | int getcurx(WINDOW *); 367 | int getcury(WINDOW *); 368 | void traceoff(void); 369 | void traceon(void); 370 | char *unctrl(chtype); 371 | int crmode(void); 372 | int nocrmode(void); 373 | int draino(int); 374 | int resetterm(void); 375 | int fixterm(void); 376 | int saveterm(void); 377 | int setsyx(int, int); 378 | int mouse_set(unsigned long); 379 | int mouse_on(unsigned long); 380 | int mouse_off(unsigned long); 381 | int request_mouse_pos(void); 382 | int map_button(unsigned long); 383 | void wmouse_position(WINDOW *, int *, int *); 384 | unsigned long getmouse(void); 385 | unsigned long getbmap(void); 386 | int assume_default_colors(int, int); 387 | const char *curses_version(void); 388 | bool has_key(int); 389 | int use_default_colors(void); 390 | int wresize(WINDOW *, int, int); 391 | int mouseinterval(int); 392 | mmask_t mousemask(mmask_t, mmask_t *); 393 | bool mouse_trafo(int *, int *, bool); 394 | int nc_getmouse(MEVENT *); 395 | int ungetmouse(MEVENT *); 396 | bool wenclose(const WINDOW *, int, int); 397 | bool wmouse_trafo(const WINDOW *, int *, int *, bool); 398 | int addrawch(chtype); 399 | int insrawch(chtype); 400 | bool is_termresized(void); 401 | int mvaddrawch(int, int, chtype); 402 | int mvdeleteln(int, int); 403 | int mvinsertln(int, int); 404 | int mvinsrawch(int, int, chtype); 405 | int mvwaddrawch(WINDOW *, int, int, chtype); 406 | int mvwdeleteln(WINDOW *, int, int); 407 | int mvwinsertln(WINDOW *, int, int); 408 | int mvwinsrawch(WINDOW *, int, int, chtype); 409 | int raw_output(bool); 410 | int resize_term(int, int); 411 | WINDOW *resize_window(WINDOW *, int, int); 412 | int waddrawch(WINDOW *, chtype); 413 | int winsrawch(WINDOW *, chtype); 414 | char wordchar(void); 415 | void PDC_debug(const char *, ...); 416 | int PDC_ungetch(int); 417 | int PDC_set_blink(bool); 418 | int PDC_set_line_color(short); 419 | void PDC_set_title(const char *); 420 | int PDC_clearclipboard(void); 421 | int PDC_freeclipboard(char *); 422 | int PDC_getclipboard(char **, long *); 423 | int PDC_setclipboard(const char *, long); 424 | unsigned long PDC_get_input_fd(void); 425 | unsigned long PDC_get_key_modifiers(void); 426 | int PDC_return_key_modifiers(bool); 427 | int PDC_save_key_modifiers(bool); 428 | void PDC_set_resize_limits( const int new_min_lines, 429 | const int new_max_lines, 430 | const int new_min_cols, 431 | const int new_max_cols); 432 | WINDOW *Xinitscr(int, char **); 433 | int COLOR_PAIR(int); 434 | ]] 435 | 436 | ffi.cdef("typedef uint64_t chtype;") 437 | ffi.cdef(header) 438 | 439 | local lib = assert(ffi.load(jit.os == "Windows" and "pdcurses" or "ncursesw")) 440 | 441 | local curses = { 442 | lib = lib, 443 | } 444 | 445 | function curses.freeconsole() 446 | if jit.os == "Windows" then 447 | ffi.cdef("int FreeConsole();") 448 | ffi.C.FreeConsole() 449 | end 450 | end 451 | 452 | if jit.os == "Windows" then 453 | -- use pdcurses for real windows! 454 | 455 | curses.COLOR_BLACK = 0 456 | 457 | curses.COLOR_RED = 4 458 | curses.COLOR_GREEN = 2 459 | curses.COLOR_YELLOW = 6 460 | 461 | curses.COLOR_BLUE = 1 462 | curses.COLOR_MAGENTA = 5 463 | curses.COLOR_CYAN = 3 464 | 465 | curses.COLOR_WHITE = 7 466 | 467 | curses.A_REVERSE = 67108864ULL 468 | curses.A_BOLD = 268435456ULL 469 | curses.A_DIM = 2147483648ULL 470 | curses.A_STANDOUT = bit.bor(curses.A_REVERSE, curses.A_BOLD) 471 | 472 | function curses.COLOR_PAIR(x) 473 | return bit.band(bit.lshift(ffi.cast("chtype", x), 33), 18446744065119617024ULL) 474 | end 475 | else 476 | curses.COLOR_BLACK = 0 477 | curses.COLOR_RED = 1 478 | curses.COLOR_GREEN = 2 479 | curses.COLOR_YELLOW = 3 480 | curses.COLOR_BLUE = 4 481 | curses.COLOR_MAGENTA = 5 482 | curses.COLOR_CYAN = 6 483 | curses.COLOR_WHITE = 7 484 | 485 | curses.A_DIM = 2 ^ 12 486 | curses.A_BOLD = 2 ^ 13 487 | curses.A_STANDOUT = 2 ^ 8 488 | end 489 | 490 | -- lua curses compat 491 | 492 | setmetatable(curses, {__index = lib}) 493 | 494 | curses.color_pair = curses.COLOR_PAIR 495 | 496 | local window_meta = {} 497 | window_meta.__index = window_meta 498 | window_meta.__call = function(s) return s end 499 | 500 | for line in header:gmatch("(.-);") do 501 | if line:find("WINDOW", nil, true) then 502 | local func = line:match(" (.+)%(") 503 | if func then 504 | local name = func 505 | if name:sub(1,1) == "w" then 506 | name = name:sub(2) 507 | elseif func:sub(1,3) == "mvw" then 508 | name = "mv" .. name:sub(4) 509 | end 510 | pcall(function() window_meta[name] = lib[func] end) 511 | end 512 | end 513 | end 514 | 515 | ffi.metatype(ffi.typeof("WINDOW"), window_meta) 516 | 517 | return curses 518 | -------------------------------------------------------------------------------- /curses/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /curses/readme.md: -------------------------------------------------------------------------------- 1 | #TODO 2 | 3 | I can't get this to run after being built. The library is also heavily macro based and is difficult to work with. 4 | 5 | On Windows I use pdcurses which is slightly different from ncurses. 6 | -------------------------------------------------------------------------------- /enet/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.setenv("NIXPKGS_ALLOW_BROKEN", "1") 5 | 6 | local header = ffibuild.NixBuild({ 7 | package_name = "enet", 8 | src = [[ 9 | #include "enet/enet.h" 10 | ]]}) 11 | 12 | local meta_data = ffibuild.GetMetaData(header) 13 | 14 | meta_data.functions.enet_socketset_select.arguments[2] = ffibuild.CreateType("type", "void *") 15 | meta_data.functions.enet_socketset_select.arguments[3] = ffibuild.CreateType("type", "void *") 16 | 17 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^enet_") end, function(name) return name:find("^ENET_") end, true, true) 18 | 19 | local lua = ffibuild.StartLibrary(header) 20 | 21 | lua = lua .. "library = " .. meta_data:BuildFunctions("^enet_(.+)", "foo_bar", "FooBar") 22 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^ENET_(.+)") 23 | 24 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /enet/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /freeimage/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | local header = ffibuild.NixBuild({ 5 | package_name = "freeimage", 6 | library_name = "libfreeimage*", 7 | src = [[ 8 | #include "FreeImage.h" 9 | ]]}) 10 | 11 | 12 | local meta_data = ffibuild.GetMetaData(header) 13 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^FreeImage_") end, function(name) return name:find("^FI") end, true, true) 14 | local lua = ffibuild.StartLibrary(header) 15 | 16 | meta_data.functions.FreeImage_RegisterExternalPlugin = nil 17 | 18 | lua = lua .. "library = " .. meta_data:BuildFunctions("^FreeImage_(.+)") 19 | 20 | do -- enums 21 | lua = lua .. "library.e = {\n" 22 | for basic_type, type in pairs(meta_data.enums) do 23 | for i, enum in ipairs(type.enums) do 24 | local friendly = enum.key:match("^FI(.+)") 25 | if friendly then 26 | if friendly:find("^T_") then 27 | friendly = friendly:gsub("^T", "IMAGE_TYPE") 28 | elseif friendly:find("^CC_") then 29 | friendly = friendly:gsub("^CC", "COLOR_CHANNEL") 30 | elseif friendly:find("^C_") then 31 | friendly = friendly:gsub("^C", "COLOR_TYPE") 32 | elseif friendly:find("^F_") then 33 | friendly = friendly:gsub("^F", "FORMAT") 34 | elseif friendly:find("^Q_") then 35 | friendly = friendly:gsub("^Q", "QUANTIZE") 36 | elseif friendly:find("^LTER_") then 37 | friendly = friendly:gsub("^LTER", "IMAGE_FILTER") 38 | elseif friendly:find("^D_") then 39 | friendly = friendly:gsub("^D", "DITHER") 40 | elseif friendly:find("^MD_") then 41 | friendly = friendly:gsub("^MD", "METADATA") 42 | elseif friendly:find("^DT_") then 43 | friendly = friendly:gsub("^DT", "METADATA_TYPE") 44 | elseif friendly:find("^JPEG_OP_") then 45 | friendly = friendly:gsub("^JPEG_OP", "JPEG_OPERATION") 46 | elseif friendly:find("^JPEG_OP_") then 47 | friendly = friendly:gsub("^JPEG_OP", "JPEG_OPERATION") 48 | elseif friendly:find("^TMO_") then 49 | friendly = friendly:gsub("^TMO", "TONEMAP_OPERATOR") 50 | end 51 | lua = lua .. "\t" .. friendly .. " = ffi.cast(\""..basic_type.."\", \""..enum.key.."\"),\n" 52 | end 53 | end 54 | end 55 | lua = lua .. "}\n" 56 | end 57 | 58 | lua = lua .. [[ 59 | do 60 | local function pow2ceil(n) 61 | return 2 ^ math.ceil(math.log(n) / math.log(2)) 62 | end 63 | 64 | local function create_mip_map(bitmap, w, h, div) 65 | local width = pow2ceil(w) 66 | local height = pow2ceil(h) 67 | 68 | local size = width > height and width or height 69 | 70 | size = size / (2 ^ div) 71 | 72 | local new_bitmap = ffi.gc(library.Rescale(bitmap, size, size, library.e.IMAGE_FILTER_BILINEAR), library.Unload) 73 | 74 | return { 75 | data = library.GetBits(new_bitmap), 76 | size = library.GetMemorySize(new_bitmap), 77 | width = size, 78 | height = size, 79 | new_bitmap = new_bitmap, 80 | } 81 | end 82 | 83 | function library.LoadImageMipMaps(file_name, flags, format) 84 | local file = io.open(file_name, "rb") 85 | local data = file:read("*all") 86 | file:close() 87 | 88 | local buffer = ffi.cast("unsigned char *", data) 89 | 90 | local stream = library.OpenMemory(buffer, #data) 91 | local type = format or library.GetFileTypeFromMemory(stream, #data) 92 | 93 | local temp = library.LoadFromMemory(type, stream, flags or 0) 94 | local bitmap = library.ConvertTo32Bits(temp) 95 | 96 | 97 | local width = library.GetWidth(bitmap) 98 | local height = library.GetHeight(bitmap) 99 | 100 | local images = {} 101 | 102 | for level = 0, math.floor(math.log(math.max(width, height)) / math.log(2)) do 103 | images[level] = create_mip_map(bitmap, width, height, level) 104 | end 105 | 106 | library.Unload(bitmap) 107 | library.Unload(temp) 108 | 109 | library.CloseMemory(stream) 110 | 111 | return images 112 | end 113 | end 114 | 115 | function library.LoadImage(data) 116 | local stream_buffer = ffi.cast("unsigned char *", data) 117 | local stream = library.OpenMemory(stream_buffer, #data) 118 | 119 | local type = library.GetFileTypeFromMemory(stream, #data) 120 | 121 | if type == library.e.FORMAT_UNKNOWN or type > library.e.FORMAT_RAW then -- huh... 122 | library.CloseMemory(stream) 123 | error("unknown format", 2) 124 | end 125 | 126 | local bitmap = library.LoadFromMemory(type, stream, 0) 127 | 128 | local image_type = library.GetImageType(bitmap) 129 | local color_type = library.GetColorType(bitmap) 130 | 131 | stream_buffer = nil 132 | 133 | local format = "bgra" 134 | local type = "unsigned_byte" 135 | 136 | if color_type == library.e.COLOR_TYPE_RGBALPHA then 137 | format = "bgra" 138 | elseif color_type == library.e.COLOR_TYPE_RGB then 139 | format = "bgr" 140 | elseif color_type == library.e.COLOR_TYPE_MINISBLACK or color_type == library.e.COLOR_TYPE_MINISWHITE then 141 | format = "r" 142 | else 143 | bitmap = library.ConvertTo32Bits(bitmap) 144 | 145 | format = "bgra" 146 | wlog("unhandled freeimage color type: %s\nconverting to 8bit rgba", color_type) 147 | end 148 | 149 | ffi.gc(bitmap, library.Unload) 150 | 151 | if image_type == library.e.IMAGE_TYPE_BITMAP then 152 | type = "unsigned_byte" 153 | elseif image_type == library.e.IMAGE_TYPE_RGBF then 154 | type = "float" 155 | format = "rgb" 156 | elseif image_type == library.e.IMAGE_TYPE_RGBAF then 157 | type = "float" 158 | format = "rgba" 159 | else 160 | wlog("unhandled freeimage format type: %s", image_type) 161 | end 162 | 163 | -- the image type of some png images are RGB but bpp is actuall 32bit (RGBA) 164 | local bpp = library.GetBPP(bitmap) 165 | 166 | if bpp == 32 then 167 | format = "bgra" 168 | end 169 | 170 | local ret = { 171 | buffer = library.GetBits(bitmap), 172 | width = library.GetWidth(bitmap), 173 | height = library.GetHeight(bitmap), 174 | format = format, 175 | type = type, 176 | } 177 | 178 | library.CloseMemory(stream) 179 | 180 | return ret 181 | end 182 | 183 | function library.LoadMultiPageImage(data, flags) 184 | local buffer = ffi.cast("unsigned char *", data) 185 | 186 | local stream = library.OpenMemory(buffer, #data) 187 | local type = library.GetFileTypeFromMemory(stream, #data) 188 | 189 | local temp = library.LoadMultiBitmapFromMemory(type, stream, flags or 0) 190 | local count = library.GetPageCount(temp) 191 | 192 | local out = {} 193 | 194 | for page = 0, count - 1 do 195 | local temp = library.LockPage(temp, page) 196 | local bitmap = library.ConvertTo32Bits(temp) 197 | 198 | local tag = ffi.new("struct FITAG *[1]") 199 | library.GetMetadata(library.e.METADATA_ANIMATION, bitmap, "FrameLeft", tag) 200 | local x = tonumber(ffi.cast("int", library.GetTagValue(tag[0]))) 201 | 202 | library.GetMetadata(library.e.METADATA_ANIMATION, bitmap, "FrameTop", tag) 203 | local y = tonumber(ffi.cast("int", library.GetTagValue(tag[0]))) 204 | 205 | library.GetMetadata(library.e.METADATA_ANIMATION, bitmap, "FrameTime", tag) 206 | local ms = tonumber(ffi.cast("int", library.GetTagValue(tag[0]))) / 1000 207 | 208 | library.DeleteTag(tag[0]) 209 | 210 | local data = library.GetBits(bitmap) 211 | local width = library.GetWidth(bitmap) 212 | local height = library.GetHeight(bitmap) 213 | 214 | ffi.gc(bitmap, library.Unload) 215 | 216 | table.insert(out, {w = width, h = height, x = x, y = y, ms = ms, data = data}) 217 | end 218 | 219 | library.CloseMultiBitmap(temp, 0) 220 | 221 | return out 222 | end 223 | 224 | function library.ImageToBuffer(data, format, force_32bit) 225 | format = format or "png" 226 | 227 | local bitmap = library.ConvertFromRawBits(data.buffer, data.width, data.height, data.width * #data.format, #data.format * 8, 0,0,0,0) 228 | local temp 229 | if force_32bit then 230 | temp = bitmap 231 | bitmap = library.ConvertTo32Bits(temp) 232 | end 233 | 234 | local mem = library.OpenMemory(nil, 0) 235 | library.SaveToMemory(library.e["FORMAT_" .. format:upper()], bitmap, mem, 0) 236 | local size = library.TellMemory(mem) 237 | local buffer_box = ffi.new("uint8_t *[1]") 238 | local size_box = ffi.new("unsigned int[1]") 239 | local out_buffer = ffi.new("uint8_t[?]", size) 240 | buffer_box[0] = out_buffer 241 | size_box[0] = size 242 | library.AcquireMemory(mem, buffer_box, size_box) 243 | 244 | library.Unload(bitmap) 245 | if temp then library.Unload(temp) end 246 | library.CloseMemory(mem) 247 | 248 | return buffer_box[0], size_box[0] 249 | end 250 | ]] 251 | 252 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /freeimage/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /freetype/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | local header = ffibuild.NixBuild({ 5 | package_name = "freetype", 6 | src = [[ 7 | #include 8 | 9 | typedef struct _FT_Glyph_Class {} FT_Glyph_Class; 10 | 11 | #include FT_CONFIG_CONFIG_H 12 | #include FT_LZW_H 13 | #include FT_CONFIG_STANDARD_LIBRARY_H 14 | #include FT_BZIP2_H 15 | #include FT_CONFIG_OPTIONS_H 16 | #include FT_WINFONTS_H 17 | #include FT_CONFIG_MODULES_H 18 | #include FT_GLYPH_H 19 | #include FT_FREETYPE_H 20 | #include FT_BITMAP_H 21 | #include FT_ERRORS_H 22 | #include FT_BBOX_H 23 | #include FT_MODULE_ERRORS_H 24 | #include FT_CACHE_H 25 | #include FT_SYSTEM_H 26 | #include FT_CACHE_IMAGE_H 27 | #include FT_IMAGE_H 28 | #include FT_CACHE_SMALL_BITMAPS_H 29 | #include FT_TYPES_H 30 | #include FT_CACHE_CHARMAP_H 31 | #include FT_LIST_H 32 | //#include FT_MAC_H 33 | #include FT_OUTLINE_H 34 | #include FT_BDF_H 35 | #include FT_MULTIPLE_MASTERS_H 36 | #include FT_SIZES_H 37 | #include FT_SFNT_NAMES_H 38 | #include FT_MODULE_H 39 | #include FT_OPENTYPE_VALIDATE_H 40 | #include FT_RENDER_H 41 | #include FT_GX_VALIDATE_H 42 | #include FT_AUTOHINTER_H 43 | #include FT_PFR_H 44 | #include FT_CFF_DRIVER_H 45 | #include FT_STROKER_H 46 | #include FT_TRUETYPE_DRIVER_H 47 | #include FT_SYNTHESIS_H 48 | #include FT_TYPE1_TABLES_H 49 | #include FT_FONT_FORMATS_H 50 | #include FT_TRUETYPE_IDS_H 51 | #include FT_TRIGONOMETRY_H 52 | #include FT_TRUETYPE_TABLES_H 53 | #include FT_LCD_FILTER_H 54 | #include FT_TRUETYPE_TAGS_H 55 | #include FT_UNPATENTED_HINTING_H 56 | #include FT_INCREMENTAL_H 57 | #include FT_CID_H 58 | #include FT_GASP_H 59 | #include FT_GZIP_H 60 | #include FT_ADVANCES_H 61 | ]]}) 62 | 63 | local meta_data = ffibuild.GetMetaData(header) 64 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^FT_") end, function(name) return name:find("^FT_") or name:find("^BDF_") end, true, true) 65 | local lua = ffibuild.StartLibrary(header) 66 | 67 | lua = lua .. "library = " .. meta_data:BuildFunctions("^FT_(.+)", "Foo_Bar", "FooBar") 68 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^FT_(.+)") 69 | 70 | lua = lua .. "local error_code_to_str = {\n" 71 | 72 | for _, enums in pairs(meta_data.global_enums) do 73 | for _, enum in ipairs(enums.enums) do 74 | local err = enum.key:match("^FT_Err_(.+)") 75 | if err then 76 | err = err:gsub("_", " "):lower() 77 | lua = lua .. "\t[" .. enum.val .. "] = \"" .. err .. "\",\n" 78 | end 79 | end 80 | end 81 | 82 | lua = lua .. "}\n" 83 | lua = lua .. "function library.ErrorCodeToString(code) return error_code_to_str[code] end\n" 84 | 85 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /freetype/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /generic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$1" = "clean" ]; then 4 | rm -rf repo/ 2> /dev/null 5 | mkdir ../tmp 2> /dev/null 6 | mv build.lua ../tmp/ 2> /dev/null 7 | mv make.sh ../tmp/ 2> /dev/null 8 | mv .gitignore ../tmp/ 2> /dev/null 9 | mv readme.md ../tmp/ 2> /dev/null 10 | rm -rf ./* 2> /dev/null 11 | mv ../tmp/* . 2> /dev/null 12 | mv ../tmp/.gitignore . 2> /dev/null 13 | rm -rf ../tmp 2> /dev/null 14 | exit 15 | fi 16 | 17 | LUA_DIR=../luajit/ 18 | LUA_BIN="${LUA_DIR}repo/src/luajit" 19 | echo $LUA_BIN 20 | 21 | if [ ! -f $LUA_BIN ]; then 22 | pushd $LUA_DIR 23 | make 24 | popd 25 | fi 26 | 27 | export LD_LIBRARY_PATH="." 28 | $LUA_BIN build.lua "$*" 29 | -------------------------------------------------------------------------------- /glfw/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | if not os.isdir("../vulkan/repo/include/vulkan") then 5 | os.execute("cd ../vulkan/ && make") 6 | end 7 | 8 | ffibuild.ManualBuild( 9 | "glfw", 10 | "https://github.com/glfw/glfw.git", 11 | "cmake -DBUILD_SHARED_LIBS=1 . && make" 12 | ) 13 | 14 | local header = ffibuild.ProcessSourceFileGCC([[ 15 | #include "vulkan.h" 16 | #include "GLFW/glfw3.h" 17 | #include "GLFW/glfw3native.h" 18 | ]], "-I./repo/include -I./../vulkan/repo/include/vulkan") 19 | 20 | local meta_data = ffibuild.GetMetaData(header) 21 | 22 | meta_data.functions.glfwCreateWindowSurface.return_type = ffibuild.CreateType("type", "int") 23 | meta_data.functions.glfwCreateWindowSurface.arguments[1] = ffibuild.CreateType("type", "void *") 24 | meta_data.functions.glfwCreateWindowSurface.arguments[3] = ffibuild.CreateType("type", "void *") 25 | meta_data.functions.glfwCreateWindowSurface.arguments[4] = ffibuild.CreateType("type", "void * *") 26 | 27 | meta_data.functions.glfwGetInstanceProcAddress.arguments[1] = ffibuild.CreateType("type", "void *") 28 | 29 | meta_data.functions.glfwGetPhysicalDevicePresentationSupport.arguments[1] = ffibuild.CreateType("type", "void *") 30 | meta_data.functions.glfwGetPhysicalDevicePresentationSupport.arguments[2] = ffibuild.CreateType("type", "void *") 31 | 32 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^glfw") end, function(name) return name:find("^GLFW") end, true) 33 | 34 | local lua = ffibuild.StartLibrary(header) 35 | 36 | lua = lua .. "library = " .. meta_data:BuildFunctions("^glfw(.+)") 37 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^GLFW_(.+)", "./repo/include/GLFW/glfw3.h", "GLFW_") 38 | 39 | lua = lua .. [[ 40 | function library.GetRequiredInstanceExtensions(extra) 41 | local count = ffi.new("uint32_t[1]") 42 | local array = CLIB.glfwGetRequiredInstanceExtensions(count) 43 | local out = {} 44 | for i = 0, count[0] - 1 do 45 | table.insert(out, ffi.string(array[i])) 46 | end 47 | if extra then 48 | for i,v in ipairs(extra) do 49 | table.insert(out, v) 50 | end 51 | end 52 | return out 53 | end 54 | 55 | function library.CreateWindowSurface(instance, window, huh) 56 | local box = ffi.new("struct VkSurfaceKHR_T * [1]") 57 | local status = CLIB.glfwCreateWindowSurface(instance, window, huh, ffi.cast("void **", box)) 58 | if status == 0 then 59 | return box[0] 60 | end 61 | return nil, status 62 | end 63 | ]] 64 | 65 | ffibuild.EndLibrary(lua, header) 66 | -------------------------------------------------------------------------------- /glfw/glfw.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | ffi.cdef([[struct GLFWmonitor {}; 3 | struct GLFWwindow {}; 4 | struct GLFWcursor {}; 5 | struct GLFWvidmode {int width;int height;int redBits;int greenBits;int blueBits;int refreshRate;}; 6 | struct GLFWgammaramp {unsigned short*red;unsigned short*green;unsigned short*blue;unsigned int size;}; 7 | struct GLFWimage {int width;int height;unsigned char*pixels;}; 8 | struct GLFWgamepadstate {unsigned char buttons[15];float axes[6];}; 9 | void(glfwMaximizeWindow)(struct GLFWwindow*); 10 | void(glfwRestoreWindow)(struct GLFWwindow*); 11 | unsigned long(glfwGetTimerValue)(); 12 | void(glfwDestroyCursor)(struct GLFWcursor*); 13 | const char*(glfwGetVersionString)(); 14 | void(glfwGetWindowPos)(struct GLFWwindow*,int*,int*); 15 | void(*glfwSetWindowMaximizeCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int)))(struct GLFWwindow*,int); 16 | void(*glfwSetWindowRefreshCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*)))(struct GLFWwindow*); 17 | void(glfwSetWindowShouldClose)(struct GLFWwindow*,int); 18 | const unsigned char*(glfwGetJoystickHats)(int,int*); 19 | void(glfwDestroyWindow)(struct GLFWwindow*); 20 | void(glfwSetCursorPos)(struct GLFWwindow*,double,double); 21 | void(*glfwSetCharCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,unsigned int)))(struct GLFWwindow*,unsigned int); 22 | int(glfwGetPhysicalDevicePresentationSupport)(void*,void*,unsigned int); 23 | void(*glfwSetErrorCallback(void(*cbfun)(int,const char*)))(int,const char*); 24 | int(glfwWindowShouldClose)(struct GLFWwindow*); 25 | void(glfwInitHint)(int,int); 26 | void(*glfwSetWindowIconifyCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int)))(struct GLFWwindow*,int); 27 | void(glfwGetVersion)(int*,int*,int*); 28 | int(glfwCreateWindowSurface)(void*,struct GLFWwindow*,void*,void**); 29 | void(*glfwGetInstanceProcAddress(void*,const char*))(); 30 | const char**(glfwGetRequiredInstanceExtensions)(unsigned int*); 31 | int(glfwVulkanSupported)(); 32 | void(glfwSwapInterval)(int); 33 | void(glfwSwapBuffers)(struct GLFWwindow*); 34 | struct GLFWwindow*(glfwGetCurrentContext)(); 35 | void(glfwMakeContextCurrent)(struct GLFWwindow*); 36 | double(glfwGetTime)(); 37 | const char*(glfwGetClipboardString)(struct GLFWwindow*); 38 | const float*(glfwGetJoystickAxes)(int,int*); 39 | int(glfwGetGamepadState)(int,struct GLFWgamepadstate*); 40 | void(*glfwSetWindowCloseCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*)))(struct GLFWwindow*); 41 | int(glfwUpdateGamepadMappings)(const char*); 42 | void(*glfwSetJoystickCallback(void(*cbfun)(int,int)))(int,int); 43 | void*(glfwGetJoystickUserPointer)(int); 44 | void(glfwSetJoystickUserPointer)(int,void*); 45 | const char*(glfwGetJoystickGUID)(int); 46 | struct GLFWwindow*(glfwCreateWindow)(int,int,const char*,struct GLFWmonitor*,struct GLFWwindow*); 47 | void(*glfwSetCursorEnterCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int)))(struct GLFWwindow*,int); 48 | const unsigned char*(glfwGetJoystickButtons)(int,int*); 49 | int(glfwJoystickPresent)(int); 50 | void(glfwSetWindowIcon)(struct GLFWwindow*,int,const struct GLFWimage*); 51 | void(*glfwSetMouseButtonCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,int,int)))(struct GLFWwindow*,int,int,int); 52 | void(*glfwSetCharModsCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,unsigned int,int)))(struct GLFWwindow*,unsigned int,int); 53 | void(*glfwSetKeyCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,int,int,int)))(struct GLFWwindow*,int,int,int,int); 54 | void(glfwSetCursor)(struct GLFWwindow*,struct GLFWcursor*); 55 | struct GLFWcursor*(glfwCreateStandardCursor)(int); 56 | struct GLFWcursor*(glfwCreateCursor)(const struct GLFWimage*,int,int); 57 | void(glfwGetCursorPos)(struct GLFWwindow*,double*,double*); 58 | int(glfwGetMouseButton)(struct GLFWwindow*,int); 59 | int(glfwGetKey)(struct GLFWwindow*,int); 60 | const char*(glfwGetKeyName)(int,int); 61 | void(glfwSetInputMode)(struct GLFWwindow*,int,int); 62 | int(glfwGetInputMode)(struct GLFWwindow*,int); 63 | void(glfwPostEmptyEvent)(); 64 | void(glfwPollEvents)(); 65 | void(*glfwSetWindowContentScaleCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,float,float)))(struct GLFWwindow*,float,float); 66 | void*(glfwGetWindowUserPointer)(struct GLFWwindow*); 67 | void(*glfwSetWindowFocusCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int)))(struct GLFWwindow*,int); 68 | const char*(glfwGetGamepadName)(int); 69 | void(*glfwSetWindowPosCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,int)))(struct GLFWwindow*,int,int); 70 | void(*glfwSetFramebufferSizeCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,int)))(struct GLFWwindow*,int,int); 71 | void(glfwSetWindowUserPointer)(struct GLFWwindow*,void*); 72 | void(glfwSetWindowAttrib)(struct GLFWwindow*,int,int); 73 | int(glfwGetWindowAttrib)(struct GLFWwindow*,int); 74 | int(glfwGetError)(const char**); 75 | const char*(glfwGetMonitorName)(struct GLFWmonitor*); 76 | void(glfwFocusWindow)(struct GLFWwindow*); 77 | void(glfwHideWindow)(struct GLFWwindow*); 78 | void(glfwShowWindow)(struct GLFWwindow*); 79 | void(glfwIconifyWindow)(struct GLFWwindow*); 80 | void(glfwSetWindowTitle)(struct GLFWwindow*,const char*); 81 | void(glfwSetWindowOpacity)(struct GLFWwindow*,float); 82 | float(glfwGetWindowOpacity)(struct GLFWwindow*); 83 | void(glfwGetWindowContentScale)(struct GLFWwindow*,float*,float*); 84 | void(glfwGetFramebufferSize)(struct GLFWwindow*,int*,int*); 85 | void(glfwSetWindowSize)(struct GLFWwindow*,int,int); 86 | void(glfwSetWindowAspectRatio)(struct GLFWwindow*,int,int); 87 | void(glfwSetWindowSizeLimits)(struct GLFWwindow*,int,int,int,int); 88 | void(glfwGetWindowSize)(struct GLFWwindow*,int*,int*); 89 | void(glfwSetWindowPos)(struct GLFWwindow*,int,int); 90 | void(glfwWindowHint)(int,int); 91 | void(glfwDefaultWindowHints)(); 92 | void(glfwGetMonitorPos)(struct GLFWmonitor*,int*,int*); 93 | void(glfwSetGammaRamp)(struct GLFWmonitor*,const struct GLFWgammaramp*); 94 | const struct GLFWgammaramp*(glfwGetGammaRamp)(struct GLFWmonitor*); 95 | void(glfwSetGamma)(struct GLFWmonitor*,float); 96 | const struct GLFWvidmode*(glfwGetVideoMode)(struct GLFWmonitor*); 97 | const struct GLFWvidmode*(glfwGetVideoModes)(struct GLFWmonitor*,int*); 98 | struct GLFWmonitor*(glfwGetPrimaryMonitor)(); 99 | void(*glfwSetMonitorCallback(void(*cbfun)(struct GLFWmonitor*,int)))(struct GLFWmonitor*,int); 100 | void*(glfwGetMonitorUserPointer)(struct GLFWmonitor*); 101 | void(glfwGetMonitorContentScale)(struct GLFWmonitor*,float*,float*); 102 | struct GLFWmonitor**(glfwGetMonitors)(int*); 103 | void(glfwTerminate)(); 104 | int(glfwInit)(); 105 | unsigned long(glfwGetTimerFrequency)(); 106 | void(glfwRequestWindowAttention)(struct GLFWwindow*); 107 | void(*glfwGetProcAddress(const char*))(); 108 | void(glfwSetWindowMonitor)(struct GLFWwindow*,struct GLFWmonitor*,int,int,int,int,int); 109 | void(*glfwSetDropCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,const char**)))(struct GLFWwindow*,int,const char**); 110 | struct GLFWmonitor*(glfwGetWindowMonitor)(struct GLFWwindow*); 111 | int(glfwJoystickIsGamepad)(int); 112 | void(glfwGetWindowFrameSize)(struct GLFWwindow*,int*,int*,int*,int*); 113 | const char*(glfwGetJoystickName)(int); 114 | void(glfwSetMonitorUserPointer)(struct GLFWmonitor*,void*); 115 | void(*glfwSetWindowSizeCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,int,int)))(struct GLFWwindow*,int,int); 116 | void(glfwSetTime)(double); 117 | void(glfwWaitEvents)(); 118 | int(glfwExtensionSupported)(const char*); 119 | int(glfwGetKeyScancode)(int); 120 | void(glfwGetMonitorPhysicalSize)(struct GLFWmonitor*,int*,int*); 121 | void(glfwWindowHintString)(int,const char*); 122 | void(glfwSetClipboardString)(struct GLFWwindow*,const char*); 123 | void(*glfwSetCursorPosCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,double,double)))(struct GLFWwindow*,double,double); 124 | void(*glfwSetScrollCallback(struct GLFWwindow*,void(*cbfun)(struct GLFWwindow*,double,double)))(struct GLFWwindow*,double,double); 125 | void(glfwWaitEventsTimeout)(double); 126 | ]]) 127 | local CLIB = ffi.load(_G.FFI_LIB or "glfw") 128 | local library = {} 129 | library = { 130 | MaximizeWindow = CLIB.glfwMaximizeWindow, 131 | RestoreWindow = CLIB.glfwRestoreWindow, 132 | GetTimerValue = CLIB.glfwGetTimerValue, 133 | DestroyCursor = CLIB.glfwDestroyCursor, 134 | GetVersionString = CLIB.glfwGetVersionString, 135 | GetWindowPos = CLIB.glfwGetWindowPos, 136 | SetWindowMaximizeCallback = CLIB.glfwSetWindowMaximizeCallback, 137 | SetWindowRefreshCallback = CLIB.glfwSetWindowRefreshCallback, 138 | SetWindowShouldClose = CLIB.glfwSetWindowShouldClose, 139 | GetJoystickHats = CLIB.glfwGetJoystickHats, 140 | DestroyWindow = CLIB.glfwDestroyWindow, 141 | SetCursorPos = CLIB.glfwSetCursorPos, 142 | SetCharCallback = CLIB.glfwSetCharCallback, 143 | GetPhysicalDevicePresentationSupport = CLIB.glfwGetPhysicalDevicePresentationSupport, 144 | SetErrorCallback = CLIB.glfwSetErrorCallback, 145 | WindowShouldClose = CLIB.glfwWindowShouldClose, 146 | InitHint = CLIB.glfwInitHint, 147 | SetWindowIconifyCallback = CLIB.glfwSetWindowIconifyCallback, 148 | GetVersion = CLIB.glfwGetVersion, 149 | CreateWindowSurface = CLIB.glfwCreateWindowSurface, 150 | GetInstanceProcAddress = CLIB.glfwGetInstanceProcAddress, 151 | GetRequiredInstanceExtensions = CLIB.glfwGetRequiredInstanceExtensions, 152 | VulkanSupported = CLIB.glfwVulkanSupported, 153 | SwapInterval = CLIB.glfwSwapInterval, 154 | SwapBuffers = CLIB.glfwSwapBuffers, 155 | GetCurrentContext = CLIB.glfwGetCurrentContext, 156 | MakeContextCurrent = CLIB.glfwMakeContextCurrent, 157 | GetTime = CLIB.glfwGetTime, 158 | GetClipboardString = CLIB.glfwGetClipboardString, 159 | GetJoystickAxes = CLIB.glfwGetJoystickAxes, 160 | GetGamepadState = CLIB.glfwGetGamepadState, 161 | SetWindowCloseCallback = CLIB.glfwSetWindowCloseCallback, 162 | UpdateGamepadMappings = CLIB.glfwUpdateGamepadMappings, 163 | SetJoystickCallback = CLIB.glfwSetJoystickCallback, 164 | GetJoystickUserPointer = CLIB.glfwGetJoystickUserPointer, 165 | SetJoystickUserPointer = CLIB.glfwSetJoystickUserPointer, 166 | GetJoystickGUID = CLIB.glfwGetJoystickGUID, 167 | CreateWindow = CLIB.glfwCreateWindow, 168 | SetCursorEnterCallback = CLIB.glfwSetCursorEnterCallback, 169 | GetJoystickButtons = CLIB.glfwGetJoystickButtons, 170 | JoystickPresent = CLIB.glfwJoystickPresent, 171 | SetWindowIcon = CLIB.glfwSetWindowIcon, 172 | SetMouseButtonCallback = CLIB.glfwSetMouseButtonCallback, 173 | SetCharModsCallback = CLIB.glfwSetCharModsCallback, 174 | SetKeyCallback = CLIB.glfwSetKeyCallback, 175 | SetCursor = CLIB.glfwSetCursor, 176 | CreateStandardCursor = CLIB.glfwCreateStandardCursor, 177 | CreateCursor = CLIB.glfwCreateCursor, 178 | GetCursorPos = CLIB.glfwGetCursorPos, 179 | GetMouseButton = CLIB.glfwGetMouseButton, 180 | GetKey = CLIB.glfwGetKey, 181 | GetKeyName = CLIB.glfwGetKeyName, 182 | SetInputMode = CLIB.glfwSetInputMode, 183 | GetInputMode = CLIB.glfwGetInputMode, 184 | PostEmptyEvent = CLIB.glfwPostEmptyEvent, 185 | PollEvents = CLIB.glfwPollEvents, 186 | SetWindowContentScaleCallback = CLIB.glfwSetWindowContentScaleCallback, 187 | GetWindowUserPointer = CLIB.glfwGetWindowUserPointer, 188 | SetWindowFocusCallback = CLIB.glfwSetWindowFocusCallback, 189 | GetGamepadName = CLIB.glfwGetGamepadName, 190 | SetWindowPosCallback = CLIB.glfwSetWindowPosCallback, 191 | SetFramebufferSizeCallback = CLIB.glfwSetFramebufferSizeCallback, 192 | SetWindowUserPointer = CLIB.glfwSetWindowUserPointer, 193 | SetWindowAttrib = CLIB.glfwSetWindowAttrib, 194 | GetWindowAttrib = CLIB.glfwGetWindowAttrib, 195 | GetError = CLIB.glfwGetError, 196 | GetMonitorName = CLIB.glfwGetMonitorName, 197 | FocusWindow = CLIB.glfwFocusWindow, 198 | HideWindow = CLIB.glfwHideWindow, 199 | ShowWindow = CLIB.glfwShowWindow, 200 | IconifyWindow = CLIB.glfwIconifyWindow, 201 | SetWindowTitle = CLIB.glfwSetWindowTitle, 202 | SetWindowOpacity = CLIB.glfwSetWindowOpacity, 203 | GetWindowOpacity = CLIB.glfwGetWindowOpacity, 204 | GetWindowContentScale = CLIB.glfwGetWindowContentScale, 205 | GetFramebufferSize = CLIB.glfwGetFramebufferSize, 206 | SetWindowSize = CLIB.glfwSetWindowSize, 207 | SetWindowAspectRatio = CLIB.glfwSetWindowAspectRatio, 208 | SetWindowSizeLimits = CLIB.glfwSetWindowSizeLimits, 209 | GetWindowSize = CLIB.glfwGetWindowSize, 210 | SetWindowPos = CLIB.glfwSetWindowPos, 211 | WindowHint = CLIB.glfwWindowHint, 212 | DefaultWindowHints = CLIB.glfwDefaultWindowHints, 213 | GetMonitorPos = CLIB.glfwGetMonitorPos, 214 | SetGammaRamp = CLIB.glfwSetGammaRamp, 215 | GetGammaRamp = CLIB.glfwGetGammaRamp, 216 | SetGamma = CLIB.glfwSetGamma, 217 | GetVideoMode = CLIB.glfwGetVideoMode, 218 | GetVideoModes = CLIB.glfwGetVideoModes, 219 | GetPrimaryMonitor = CLIB.glfwGetPrimaryMonitor, 220 | SetMonitorCallback = CLIB.glfwSetMonitorCallback, 221 | GetMonitorUserPointer = CLIB.glfwGetMonitorUserPointer, 222 | GetMonitorContentScale = CLIB.glfwGetMonitorContentScale, 223 | GetMonitors = CLIB.glfwGetMonitors, 224 | Terminate = CLIB.glfwTerminate, 225 | Init = CLIB.glfwInit, 226 | GetTimerFrequency = CLIB.glfwGetTimerFrequency, 227 | RequestWindowAttention = CLIB.glfwRequestWindowAttention, 228 | GetProcAddress = CLIB.glfwGetProcAddress, 229 | SetWindowMonitor = CLIB.glfwSetWindowMonitor, 230 | SetDropCallback = CLIB.glfwSetDropCallback, 231 | GetWindowMonitor = CLIB.glfwGetWindowMonitor, 232 | JoystickIsGamepad = CLIB.glfwJoystickIsGamepad, 233 | GetWindowFrameSize = CLIB.glfwGetWindowFrameSize, 234 | GetJoystickName = CLIB.glfwGetJoystickName, 235 | SetMonitorUserPointer = CLIB.glfwSetMonitorUserPointer, 236 | SetWindowSizeCallback = CLIB.glfwSetWindowSizeCallback, 237 | SetTime = CLIB.glfwSetTime, 238 | WaitEvents = CLIB.glfwWaitEvents, 239 | ExtensionSupported = CLIB.glfwExtensionSupported, 240 | GetKeyScancode = CLIB.glfwGetKeyScancode, 241 | GetMonitorPhysicalSize = CLIB.glfwGetMonitorPhysicalSize, 242 | WindowHintString = CLIB.glfwWindowHintString, 243 | SetClipboardString = CLIB.glfwSetClipboardString, 244 | SetCursorPosCallback = CLIB.glfwSetCursorPosCallback, 245 | SetScrollCallback = CLIB.glfwSetScrollCallback, 246 | WaitEventsTimeout = CLIB.glfwWaitEventsTimeout, 247 | } 248 | library.e = { 249 | APIENTRY_DEFINED = 1, 250 | WINGDIAPI_DEFINED = 1, 251 | CALLBACK_DEFINED = 1, 252 | VERSION_MAJOR = 3, 253 | VERSION_MINOR = 3, 254 | VERSION_REVISION = 0, 255 | TRUE = 1, 256 | FALSE = 0, 257 | RELEASE = 0, 258 | PRESS = 1, 259 | REPEAT = 2, 260 | HAT_CENTERED = 0, 261 | HAT_UP = 1, 262 | HAT_RIGHT = 2, 263 | HAT_DOWN = 4, 264 | HAT_LEFT = 8, 265 | HAT_RIGHT_UP = 3, 266 | HAT_RIGHT_DOWN = 6, 267 | HAT_LEFT_UP = 9, 268 | HAT_LEFT_DOWN = 12, 269 | KEY_UNKNOWN = -1, 270 | KEY_SPACE = 32, 271 | KEY_APOSTROPHE = 39, 272 | KEY_COMMA = 44, 273 | KEY_MINUS = 45, 274 | KEY_PERIOD = 46, 275 | KEY_SLASH = 47, 276 | KEY_0 = 48, 277 | KEY_1 = 49, 278 | KEY_2 = 50, 279 | KEY_3 = 51, 280 | KEY_4 = 52, 281 | KEY_5 = 53, 282 | KEY_6 = 54, 283 | KEY_7 = 55, 284 | KEY_8 = 56, 285 | KEY_9 = 57, 286 | KEY_SEMICOLON = 59, 287 | KEY_EQUAL = 61, 288 | KEY_A = 65, 289 | KEY_B = 66, 290 | KEY_C = 67, 291 | KEY_D = 68, 292 | KEY_E = 69, 293 | KEY_F = 70, 294 | KEY_G = 71, 295 | KEY_H = 72, 296 | KEY_I = 73, 297 | KEY_J = 74, 298 | KEY_K = 75, 299 | KEY_L = 76, 300 | KEY_M = 77, 301 | KEY_N = 78, 302 | KEY_O = 79, 303 | KEY_P = 80, 304 | KEY_Q = 81, 305 | KEY_R = 82, 306 | KEY_S = 83, 307 | KEY_T = 84, 308 | KEY_U = 85, 309 | KEY_V = 86, 310 | KEY_W = 87, 311 | KEY_X = 88, 312 | KEY_Y = 89, 313 | KEY_Z = 90, 314 | KEY_LEFT_BRACKET = 91, 315 | KEY_BACKSLASH = 92, 316 | KEY_RIGHT_BRACKET = 93, 317 | KEY_GRAVE_ACCENT = 96, 318 | KEY_WORLD_1 = 161, 319 | KEY_WORLD_2 = 162, 320 | KEY_ESCAPE = 256, 321 | KEY_ENTER = 257, 322 | KEY_TAB = 258, 323 | KEY_BACKSPACE = 259, 324 | KEY_INSERT = 260, 325 | KEY_DELETE = 261, 326 | KEY_RIGHT = 262, 327 | KEY_LEFT = 263, 328 | KEY_DOWN = 264, 329 | KEY_UP = 265, 330 | KEY_PAGE_UP = 266, 331 | KEY_PAGE_DOWN = 267, 332 | KEY_HOME = 268, 333 | KEY_END = 269, 334 | KEY_CAPS_LOCK = 280, 335 | KEY_SCROLL_LOCK = 281, 336 | KEY_NUM_LOCK = 282, 337 | KEY_PRINT_SCREEN = 283, 338 | KEY_PAUSE = 284, 339 | KEY_F1 = 290, 340 | KEY_F2 = 291, 341 | KEY_F3 = 292, 342 | KEY_F4 = 293, 343 | KEY_F5 = 294, 344 | KEY_F6 = 295, 345 | KEY_F7 = 296, 346 | KEY_F8 = 297, 347 | KEY_F9 = 298, 348 | KEY_F10 = 299, 349 | KEY_F11 = 300, 350 | KEY_F12 = 301, 351 | KEY_F13 = 302, 352 | KEY_F14 = 303, 353 | KEY_F15 = 304, 354 | KEY_F16 = 305, 355 | KEY_F17 = 306, 356 | KEY_F18 = 307, 357 | KEY_F19 = 308, 358 | KEY_F20 = 309, 359 | KEY_F21 = 310, 360 | KEY_F22 = 311, 361 | KEY_F23 = 312, 362 | KEY_F24 = 313, 363 | KEY_F25 = 314, 364 | KEY_KP_0 = 320, 365 | KEY_KP_1 = 321, 366 | KEY_KP_2 = 322, 367 | KEY_KP_3 = 323, 368 | KEY_KP_4 = 324, 369 | KEY_KP_5 = 325, 370 | KEY_KP_6 = 326, 371 | KEY_KP_7 = 327, 372 | KEY_KP_8 = 328, 373 | KEY_KP_9 = 329, 374 | KEY_KP_DECIMAL = 330, 375 | KEY_KP_DIVIDE = 331, 376 | KEY_KP_MULTIPLY = 332, 377 | KEY_KP_SUBTRACT = 333, 378 | KEY_KP_ADD = 334, 379 | KEY_KP_ENTER = 335, 380 | KEY_KP_EQUAL = 336, 381 | KEY_LEFT_SHIFT = 340, 382 | KEY_LEFT_CONTROL = 341, 383 | KEY_LEFT_ALT = 342, 384 | KEY_LEFT_SUPER = 343, 385 | KEY_RIGHT_SHIFT = 344, 386 | KEY_RIGHT_CONTROL = 345, 387 | KEY_RIGHT_ALT = 346, 388 | KEY_RIGHT_SUPER = 347, 389 | KEY_MENU = 348, 390 | KEY_LAST = 348, 391 | MOD_SHIFT = 1, 392 | MOD_CONTROL = 2, 393 | MOD_ALT = 4, 394 | MOD_SUPER = 8, 395 | MOD_CAPS_LOCK = 16, 396 | MOD_NUM_LOCK = 32, 397 | MOUSE_BUTTON_1 = 0, 398 | MOUSE_BUTTON_2 = 1, 399 | MOUSE_BUTTON_3 = 2, 400 | MOUSE_BUTTON_4 = 3, 401 | MOUSE_BUTTON_5 = 4, 402 | MOUSE_BUTTON_6 = 5, 403 | MOUSE_BUTTON_7 = 6, 404 | MOUSE_BUTTON_8 = 7, 405 | MOUSE_BUTTON_LAST = 7, 406 | MOUSE_BUTTON_LEFT = 0, 407 | MOUSE_BUTTON_RIGHT = 1, 408 | MOUSE_BUTTON_MIDDLE = 2, 409 | JOYSTICK_1 = 0, 410 | JOYSTICK_2 = 1, 411 | JOYSTICK_3 = 2, 412 | JOYSTICK_4 = 3, 413 | JOYSTICK_5 = 4, 414 | JOYSTICK_6 = 5, 415 | JOYSTICK_7 = 6, 416 | JOYSTICK_8 = 7, 417 | JOYSTICK_9 = 8, 418 | JOYSTICK_10 = 9, 419 | JOYSTICK_11 = 10, 420 | JOYSTICK_12 = 11, 421 | JOYSTICK_13 = 12, 422 | JOYSTICK_14 = 13, 423 | JOYSTICK_15 = 14, 424 | JOYSTICK_16 = 15, 425 | JOYSTICK_LAST = 15, 426 | GAMEPAD_BUTTON_A = 0, 427 | GAMEPAD_BUTTON_B = 1, 428 | GAMEPAD_BUTTON_X = 2, 429 | GAMEPAD_BUTTON_Y = 3, 430 | GAMEPAD_BUTTON_LEFT_BUMPER = 4, 431 | GAMEPAD_BUTTON_RIGHT_BUMPER = 5, 432 | GAMEPAD_BUTTON_BACK = 6, 433 | GAMEPAD_BUTTON_START = 7, 434 | GAMEPAD_BUTTON_GUIDE = 8, 435 | GAMEPAD_BUTTON_LEFT_THUMB = 9, 436 | GAMEPAD_BUTTON_RIGHT_THUMB = 10, 437 | GAMEPAD_BUTTON_DPAD_UP = 11, 438 | GAMEPAD_BUTTON_DPAD_RIGHT = 12, 439 | GAMEPAD_BUTTON_DPAD_DOWN = 13, 440 | GAMEPAD_BUTTON_DPAD_LEFT = 14, 441 | GAMEPAD_BUTTON_LAST = 14, 442 | GAMEPAD_BUTTON_CROSS = 0, 443 | GAMEPAD_BUTTON_CIRCLE = 1, 444 | GAMEPAD_BUTTON_SQUARE = 2, 445 | GAMEPAD_BUTTON_TRIANGLE = 3, 446 | GAMEPAD_AXIS_LEFT_X = 0, 447 | GAMEPAD_AXIS_LEFT_Y = 1, 448 | GAMEPAD_AXIS_RIGHT_X = 2, 449 | GAMEPAD_AXIS_RIGHT_Y = 3, 450 | GAMEPAD_AXIS_LEFT_TRIGGER = 4, 451 | GAMEPAD_AXIS_RIGHT_TRIGGER = 5, 452 | GAMEPAD_AXIS_LAST = 5, 453 | NO_ERROR = 0, 454 | NOT_INITIALIZED = 65537, 455 | NO_CURRENT_CONTEXT = 65538, 456 | INVALID_ENUM = 65539, 457 | INVALID_VALUE = 65540, 458 | OUT_OF_MEMORY = 65541, 459 | API_UNAVAILABLE = 65542, 460 | VERSION_UNAVAILABLE = 65543, 461 | PLATFORM_ERROR = 65544, 462 | FORMAT_UNAVAILABLE = 65545, 463 | NO_WINDOW_CONTEXT = 65546, 464 | FOCUSED = 131073, 465 | ICONIFIED = 131074, 466 | RESIZABLE = 131075, 467 | VISIBLE = 131076, 468 | DECORATED = 131077, 469 | AUTO_ICONIFY = 131078, 470 | FLOATING = 131079, 471 | MAXIMIZED = 131080, 472 | CENTER_CURSOR = 131081, 473 | TRANSPARENT_FRAMEBUFFER = 131082, 474 | HOVERED = 131083, 475 | RED_BITS = 135169, 476 | GREEN_BITS = 135170, 477 | BLUE_BITS = 135171, 478 | ALPHA_BITS = 135172, 479 | DEPTH_BITS = 135173, 480 | STENCIL_BITS = 135174, 481 | ACCUM_RED_BITS = 135175, 482 | ACCUM_GREEN_BITS = 135176, 483 | ACCUM_BLUE_BITS = 135177, 484 | ACCUM_ALPHA_BITS = 135178, 485 | AUX_BUFFERS = 135179, 486 | STEREO = 135180, 487 | SAMPLES = 135181, 488 | SRGB_CAPABLE = 135182, 489 | REFRESH_RATE = 135183, 490 | DOUBLEBUFFER = 135184, 491 | CLIENT_API = 139265, 492 | CONTEXT_VERSION_MAJOR = 139266, 493 | CONTEXT_VERSION_MINOR = 139267, 494 | CONTEXT_REVISION = 139268, 495 | CONTEXT_ROBUSTNESS = 139269, 496 | OPENGL_FORWARD_COMPAT = 139270, 497 | OPENGL_DEBUG_CONTEXT = 139271, 498 | OPENGL_PROFILE = 139272, 499 | CONTEXT_RELEASE_BEHAVIOR = 139273, 500 | CONTEXT_NO_ERROR = 139274, 501 | CONTEXT_CREATION_API = 139275, 502 | COCOA_RETINA_FRAMEBUFFER = 143361, 503 | COCOA_FRAME_NAME = 143362, 504 | COCOA_GRAPHICS_SWITCHING = 143363, 505 | X11_CLASS_NAME = 147457, 506 | X11_INSTANCE_NAME = 147458, 507 | NO_API = 0, 508 | OPENGL_API = 196609, 509 | OPENGL_ES_API = 196610, 510 | NO_ROBUSTNESS = 0, 511 | NO_RESET_NOTIFICATION = 200705, 512 | LOSE_CONTEXT_ON_RESET = 200706, 513 | OPENGL_ANY_PROFILE = 0, 514 | OPENGL_CORE_PROFILE = 204801, 515 | OPENGL_COMPAT_PROFILE = 204802, 516 | CURSOR = 208897, 517 | STICKY_KEYS = 208898, 518 | STICKY_MOUSE_BUTTONS = 208899, 519 | LOCK_KEY_MODS = 208900, 520 | CURSOR_NORMAL = 212993, 521 | CURSOR_HIDDEN = 212994, 522 | CURSOR_DISABLED = 212995, 523 | ANY_RELEASE_BEHAVIOR = 0, 524 | RELEASE_BEHAVIOR_FLUSH = 217089, 525 | RELEASE_BEHAVIOR_NONE = 217090, 526 | NATIVE_CONTEXT_API = 221185, 527 | EGL_CONTEXT_API = 221186, 528 | OSMESA_CONTEXT_API = 221187, 529 | ARROW_CURSOR = 221185, 530 | IBEAM_CURSOR = 221186, 531 | CROSSHAIR_CURSOR = 221187, 532 | HAND_CURSOR = 221188, 533 | HRESIZE_CURSOR = 221189, 534 | VRESIZE_CURSOR = 221190, 535 | CONNECTED = 262145, 536 | DISCONNECTED = 262146, 537 | JOYSTICK_HAT_BUTTONS = 327681, 538 | COCOA_CHDIR_RESOURCES = 331777, 539 | COCOA_MENUBAR = 331778, 540 | DONT_CARE = -1, 541 | } 542 | function library.GetRequiredInstanceExtensions(extra) 543 | local count = ffi.new("uint32_t[1]") 544 | local array = CLIB.glfwGetRequiredInstanceExtensions(count) 545 | local out = {} 546 | for i = 0, count[0] - 1 do 547 | table.insert(out, ffi.string(array[i])) 548 | end 549 | if extra then 550 | for i,v in ipairs(extra) do 551 | table.insert(out, v) 552 | end 553 | end 554 | return out 555 | end 556 | 557 | function library.CreateWindowSurface(instance, window, huh) 558 | local box = ffi.new("struct VkSurfaceKHR_T * [1]") 559 | local status = CLIB.glfwCreateWindowSurface(instance, window, huh, ffi.cast("void **", box)) 560 | if status == 0 then 561 | return box[0] 562 | end 563 | return nil, status 564 | end 565 | library.clib = CLIB 566 | return library 567 | -------------------------------------------------------------------------------- /glfw/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /graphene/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.checkcmds("meson", "ninja", "git") 5 | 6 | ffibuild.ManualBuild( 7 | "graphene", 8 | "https://github.com/ebassi/graphene.git", 9 | "meson build && cd build && ninja" 10 | ) 11 | 12 | local header = ffibuild.ProcessSourceFileGCC([[ 13 | #include "graphene.h" 14 | ]], "-I./repo/build/src/ -I./repo/src/") 15 | 16 | local meta_data = ffibuild.GetMetaData(header) 17 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^graphene_") end, function(name) return name:find("^GRAPHENE_") end, true, true) 18 | local lua = ffibuild.StartLibrary(header, "metatables") 19 | 20 | lua = lua .. "library = " .. meta_data:BuildFunctions("^graphene_(.+)", "foo_bar", "FooBar") 21 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^GRAPHENE_(.+)", "repo/src/graphene.h") 22 | 23 | local type_info = { 24 | --ray = 3, 25 | --triangle = 3*3, 26 | --plane = 4, 27 | vec3 = 3, 28 | --sphere = 3, 29 | --box = 4, 30 | quaternion = {0,0,0,1}, 31 | --quad = 4, 32 | --point = 2, 33 | matrix = {0,0,0,1, 0,0,1,0, 0,1,0,0, 1,0,0,0,}, 34 | euler = 3, 35 | vec2 = 2, 36 | vec4 = 4, 37 | --size = 2, 38 | point3d = 3, 39 | --frustum = 4, 40 | rect = 4, 41 | } 42 | 43 | local objects = {} 44 | 45 | for _, type in pairs(meta_data.typedefs) do 46 | local type_name = type:GetBasicType():match("struct _graphene_(.+)_t") 47 | if type_name then 48 | objects[type_name] = {meta_name = type_name, declaration = type:GetDeclaration(meta_data), functions = {}} 49 | for func_name, func_info in pairs(meta_data:GetFunctionsStartingWithType(type)) do 50 | local friendly = func_name:match("graphene_" .. type_name .. "_(.+)") 51 | friendly = ffibuild.ChangeCase(friendly, "foo_bar", "FooBar") 52 | objects[type_name].functions[friendly] = func_info 53 | end 54 | objects[type_name].functions.__gc = objects[type_name].functions.Free -- use ffi.new 55 | objects[type_name].functions.__mul = objects[type_name].functions.Multiply 56 | objects[type_name].functions.__div = objects[type_name].functions.Divide 57 | objects[type_name].functions.__add = objects[type_name].functions.Add 58 | objects[type_name].functions.__sub = objects[type_name].functions.Subtract 59 | objects[type_name].functions.__unm = objects[type_name].functions.Negate 60 | objects[type_name].functions.__len = objects[type_name].functions.Length 61 | 62 | 63 | local friendly = ffibuild.ChangeCase(type_name, "foo_bar", "FooBar") 64 | 65 | if type_name == "point3d" then 66 | lua = lua .. "library.point3d = function(x,y,z) local s = library.Point3dAlloc() s:Init(x or 0, y or 0, z or 0) return s end\n" 67 | elseif objects[type_name].functions.InitFromFloat and type_info[type_name] then 68 | local default = type_info[type_name] 69 | if _G.type(default) == "number" then 70 | local tbl = {} 71 | for i = 1, default do 72 | tbl[i] = 0 73 | end 74 | default = tbl 75 | end 76 | lua = lua .. "local float_t = ffi.typeof('float["..#default.."]')\n" 77 | 78 | local args = {} 79 | for i = 1, #default do 80 | table.insert(args, "_" .. i) 81 | end 82 | 83 | local defaults = {} 84 | for i = 1, #default do 85 | defaults[i] = "_" .. i .. " or " .. default[i] 86 | end 87 | 88 | lua = lua .. "library." .. type_name .. " = function("..table.concat(args, ", ")..") local s = library."..friendly.."Alloc() s:InitFromFloat(float_t("..table.concat(defaults, ", ") ..")) return s end\n" 89 | else 90 | lua = lua .. "library." .. type_name .. " = library."..friendly.."Alloc\n" 91 | end 92 | end 93 | end 94 | 95 | for _, info in pairs(objects) do 96 | lua = lua .. meta_data:BuildLuaMetaTable(info.meta_name, info.declaration, info.functions, argument_translate, return_translate, nil, true) 97 | end 98 | 99 | os.execute("cp -L repo/build/src/libgraphene-1.0.so libgraphene.so") 100 | 101 | ffibuild.EndLibrary(lua, header) 102 | -------------------------------------------------------------------------------- /graphene/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /libarchive/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | local header = ffibuild.NixBuild({ 5 | package_name = "libarchive", 6 | library_name = "libarchive", 7 | src = [[ 8 | #include "archive.h" 9 | #include "archive_entry.h" 10 | ]]}) 11 | 12 | local meta_data = ffibuild.GetMetaData(header) 13 | meta_data.functions.archive_entry_acl_next_w = nil 14 | meta_data.functions.archive_write_open_FILE.arguments[2] = ffibuild.CreateType("type", "void *") 15 | meta_data.functions.archive_read_open_FILE.arguments[2] = ffibuild.CreateType("type", "void *") 16 | meta_data.functions.archive_entry_copy_stat.arguments[2] = ffibuild.CreateType("type", "void *") 17 | meta_data.functions.archive_read_disk_entry_from_file.arguments[4] = ffibuild.CreateType("type", "const void *") 18 | meta_data.functions.archive_entry_stat.return_type = ffibuild.CreateType("type", "void *") 19 | 20 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^archive_") end, function(name) return name:find("^ARCHIVE_") end, true, true) 21 | 22 | local lua = ffibuild.StartLibrary(header) 23 | 24 | lua = lua .. "library = " .. meta_data:BuildFunctions("^archive_(.+)", "foo_bar", "FooBar") 25 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^ARCHIVE_(.+)", "./include/archive.h", "ARCHIVE_") 26 | 27 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /libarchive/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /libmp3lame/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.setenv("NIXPKGS_ALLOW_BROKEN", "1") 5 | 6 | local header = ffibuild.NixBuild({ 7 | package_name = "lame", 8 | library_name = "libmp3lame", 9 | src = [[ 10 | #include "lame/lame.h" 11 | ]] 12 | }) 13 | 14 | local meta_data = ffibuild.GetMetaData(header) 15 | 16 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^lame_") end, function(name) return name:find("^LAME_") end, true, true) 17 | 18 | local lua = ffibuild.StartLibrary(header) 19 | 20 | lua = lua .. "library = " .. meta_data:BuildFunctions("^lame_(.+)", "foo_bar", "FooBar") 21 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^LAME_(.+)") 22 | 23 | ffibuild.EndLibrary(lua, header) 24 | -------------------------------------------------------------------------------- /libmp3lame/libmp3lame.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | ffi.cdef([[typedef enum lame_errorcodes_t{LAME_OKAY=0,LAME_NOERROR=0,LAME_GENERICERROR=-1,LAME_NOMEM=-10,LAME_BADBITRATE=-11,LAME_BADSAMPFREQ=-12,LAME_INTERNALERROR=-13}; 3 | struct _IO_marker {struct _IO_marker*_next;struct _IO_FILE*_sbuf;int _pos;}; 4 | struct _IO_FILE {int _flags;char*_IO_read_ptr;char*_IO_read_end;char*_IO_read_base;char*_IO_write_base;char*_IO_write_ptr;char*_IO_write_end;char*_IO_buf_base;char*_IO_buf_end;char*_IO_save_base;char*_IO_backup_base;char*_IO_save_end;struct _IO_marker*_markers;struct _IO_FILE*_chain;int _fileno;int _flags2;long _old_offset;unsigned short _cur_column;signed char _vtable_offset;char _shortbuf[1];void*_lock;long _offset;void*__pad1;void*__pad2;void*__pad3;void*__pad4;unsigned long __pad5;int _mode;char _unused2[15*sizeof(int)-4*sizeof(void*)-sizeof(size_t)];}; 5 | struct lame_global_struct {}; 6 | float(lame_get_ATHlower)(const struct lame_global_struct*); 7 | float(lame_get_athaa_sensitivity)(const struct lame_global_struct*); 8 | void(lame_set_msfix)(struct lame_global_struct*,double); 9 | int(lame_get_decode_on_the_fly)(const struct lame_global_struct*); 10 | int(lame_set_ATHlower)(struct lame_global_struct*,float); 11 | int(lame_get_noATH)(const struct lame_global_struct*); 12 | int(lame_get_ATHtype)(const struct lame_global_struct*); 13 | int(lame_set_decode_on_the_fly)(struct lame_global_struct*,int); 14 | int(lame_encode_buffer_ieee_float)(struct lame_global_struct*,const float,const float,const int,unsigned char*,const int); 15 | int(lame_set_ATHshort)(struct lame_global_struct*,int); 16 | int(lame_set_ATHtype)(struct lame_global_struct*,int); 17 | struct lame_global_struct*(lame_init)(); 18 | int(lame_set_scale)(struct lame_global_struct*,float); 19 | int(lame_get_ATHshort)(const struct lame_global_struct*); 20 | int(lame_set_debugf)(struct lame_global_struct*,void(*unknown_2)(const char*,__builtin_va_list)); 21 | int(lame_get_samplerate)(int,int); 22 | float(lame_get_noclipScale)(const struct lame_global_struct*); 23 | int(lame_get_in_samplerate)(const struct lame_global_struct*); 24 | int(lame_set_in_samplerate)(struct lame_global_struct*,int); 25 | int(lame_set_VBR_mean_bitrate_kbps)(struct lame_global_struct*,int); 26 | int(lame_set_num_channels)(struct lame_global_struct*,int); 27 | int(lame_get_num_channels)(const struct lame_global_struct*); 28 | float(lame_get_msfix)(const struct lame_global_struct*); 29 | int(lame_get_bitrate)(int,int); 30 | float(lame_get_interChRatio)(const struct lame_global_struct*); 31 | int(lame_set_extension)(struct lame_global_struct*,int); 32 | int(lame_set_findReplayGain)(struct lame_global_struct*,int); 33 | void(lame_bitrate_hist)(const struct lame_global_struct*,int); 34 | int(lame_get_extension)(const struct lame_global_struct*); 35 | int(lame_get_useTemporal)(const struct lame_global_struct*); 36 | int(lame_get_version)(const struct lame_global_struct*); 37 | int(lame_set_preset)(struct lame_global_struct*,int); 38 | int(lame_set_force_ms)(struct lame_global_struct*,int); 39 | int(lame_get_force_ms)(const struct lame_global_struct*); 40 | int(lame_get_lowpassfreq)(const struct lame_global_struct*); 41 | int(lame_encode_flush)(struct lame_global_struct*,unsigned char*,int); 42 | int(lame_get_size_mp3buffer)(const struct lame_global_struct*); 43 | int(lame_set_highpasswidth)(struct lame_global_struct*,int); 44 | int(lame_get_noclipGainChange)(const struct lame_global_struct*); 45 | int(lame_get_VBR_max_bitrate_kbps)(const struct lame_global_struct*); 46 | int(lame_set_ATHonly)(struct lame_global_struct*,int); 47 | int(lame_set_VBR)(struct lame_global_struct*,enum vbr_mode_e); 48 | int(lame_get_highpassfreq)(const struct lame_global_struct*); 49 | int(lame_set_scale_right)(struct lame_global_struct*,float); 50 | int(lame_get_ATHonly)(const struct lame_global_struct*); 51 | int(lame_set_free_format)(struct lame_global_struct*,int); 52 | int(lame_set_experimentalY)(struct lame_global_struct*,int); 53 | int(lame_get_quant_comp)(const struct lame_global_struct*); 54 | int(lame_get_quant_comp_short)(const struct lame_global_struct*); 55 | int(lame_get_framesize)(const struct lame_global_struct*); 56 | int(lame_set_quant_comp)(struct lame_global_struct*,int); 57 | int(lame_encode_buffer_int)(struct lame_global_struct*,const int,const int,const int,unsigned char*,const int); 58 | int(lame_set_allow_diff_short)(struct lame_global_struct*,int); 59 | int(lame_set_quant_comp_short)(struct lame_global_struct*,int); 60 | enum MPEG_mode_e(lame_get_mode)(const struct lame_global_struct*); 61 | int(lame_get_allow_diff_short)(const struct lame_global_struct*); 62 | int(lame_get_out_samplerate)(const struct lame_global_struct*); 63 | void(lame_bitrate_stereo_mode_hist)(const struct lame_global_struct*,int); 64 | int(lame_get_VBR_q)(const struct lame_global_struct*); 65 | int(lame_set_noATH)(struct lame_global_struct*,int); 66 | int(lame_init_bitstream)(struct lame_global_struct*); 67 | int(lame_set_error_protection)(struct lame_global_struct*,int); 68 | float(lame_get_scale)(const struct lame_global_struct*); 69 | int(lame_set_exp_nspsytune)(struct lame_global_struct*,int); 70 | int(lame_set_lowpasswidth)(struct lame_global_struct*,int); 71 | int(lame_close)(struct lame_global_struct*); 72 | int(lame_get_encoder_padding)(const struct lame_global_struct*); 73 | int(lame_get_AudiophileGain)(const struct lame_global_struct*); 74 | int(lame_get_error_protection)(const struct lame_global_struct*); 75 | int(lame_get_frameNum)(const struct lame_global_struct*); 76 | int(lame_get_encoder_delay)(const struct lame_global_struct*); 77 | int(lame_encode_buffer_ieee_double)(struct lame_global_struct*,const double,const double,const int,unsigned char*,const int); 78 | int(lame_get_brate)(const struct lame_global_struct*); 79 | enum vbr_mode_e(lame_get_VBR)(const struct lame_global_struct*); 80 | int(lame_set_original)(struct lame_global_struct*,int); 81 | int(lame_get_strict_ISO)(const struct lame_global_struct*); 82 | int(lame_get_write_id3tag_automatic)(const struct lame_global_struct*); 83 | unsigned long(lame_get_id3v2_tag)(struct lame_global_struct*,unsigned char*,unsigned long); 84 | int(lame_set_errorf)(struct lame_global_struct*,void(*unknown_2)(const char*,__builtin_va_list)); 85 | int(lame_encode_flush_nogap)(struct lame_global_struct*,unsigned char*,int); 86 | unsigned long(lame_get_id3v1_tag)(struct lame_global_struct*,unsigned char*,unsigned long); 87 | float(lame_get_PeakSample)(const struct lame_global_struct*); 88 | int(lame_set_num_samples)(struct lame_global_struct*,unsigned long); 89 | int(lame_encode_buffer_long)(struct lame_global_struct*,const long,const long,const int,unsigned char*,const int); 90 | int(lame_set_compression_ratio)(struct lame_global_struct*,float); 91 | void(lame_bitrate_kbps)(const struct lame_global_struct*,int); 92 | void(lame_mp3_tags_fid)(struct lame_global_struct*,struct _IO_FILE*); 93 | int(lame_set_VBR_quality)(struct lame_global_struct*,float); 94 | int(lame_get_no_short_blocks)(const struct lame_global_struct*); 95 | void(lame_bitrate_block_type_hist)(const struct lame_global_struct*,int); 96 | void(lame_block_type_hist)(const struct lame_global_struct*,int); 97 | void(lame_stereo_mode_hist)(const struct lame_global_struct*,int); 98 | int(lame_encode_buffer_long2)(struct lame_global_struct*,const long,const long,const int,unsigned char*,const int); 99 | int(lame_set_no_short_blocks)(struct lame_global_struct*,int); 100 | float(lame_get_VBR_quality)(const struct lame_global_struct*); 101 | int(lame_encode_buffer_interleaved_ieee_double)(struct lame_global_struct*,const double,const int,unsigned char*,const int); 102 | int(lame_encode_buffer_interleaved_ieee_float)(struct lame_global_struct*,const float,const int,unsigned char*,const int); 103 | int(lame_encode_buffer_float)(struct lame_global_struct*,const float,const float,const int,unsigned char*,const int); 104 | int(lame_encode_buffer_interleaved)(struct lame_global_struct*,short,int,unsigned char*,int); 105 | int(lame_set_disable_reservoir)(struct lame_global_struct*,int); 106 | void(lame_print_internals)(const struct lame_global_struct*); 107 | int(lame_get_quality)(const struct lame_global_struct*); 108 | int(lame_set_experimentalZ)(struct lame_global_struct*,int); 109 | void(lame_print_config)(const struct lame_global_struct*); 110 | int(lame_set_strict_ISO)(struct lame_global_struct*,int); 111 | int(lame_get_mf_samples_to_encode)(const struct lame_global_struct*); 112 | int(lame_get_athaa_type)(const struct lame_global_struct*); 113 | int(lame_init_params)(struct lame_global_struct*); 114 | int(lame_set_out_samplerate)(struct lame_global_struct*,int); 115 | int(lame_get_disable_reservoir)(const struct lame_global_struct*); 116 | int(lame_get_force_short_blocks)(const struct lame_global_struct*); 117 | int(lame_get_analysis)(const struct lame_global_struct*); 118 | void(lame_set_write_id3tag_automatic)(struct lame_global_struct*,int); 119 | unsigned long(lame_get_lametag_frame)(const struct lame_global_struct*,unsigned char*,unsigned long); 120 | int(lame_set_bWriteVbrTag)(struct lame_global_struct*,int); 121 | int(lame_set_athaa_type)(struct lame_global_struct*,int); 122 | int(lame_set_asm_optimizations)(struct lame_global_struct*,int,int); 123 | int(lame_set_analysis)(struct lame_global_struct*,int); 124 | int(lame_set_scale_left)(struct lame_global_struct*,float); 125 | int(lame_get_nogap_total)(const struct lame_global_struct*); 126 | float(lame_get_compression_ratio)(const struct lame_global_struct*); 127 | int(lame_get_VBR_hard_min)(const struct lame_global_struct*); 128 | int(lame_get_highpasswidth)(const struct lame_global_struct*); 129 | int(lame_set_brate)(struct lame_global_struct*,int); 130 | int(lame_set_VBR_min_bitrate_kbps)(struct lame_global_struct*,int); 131 | int(lame_get_nogap_currentindex)(const struct lame_global_struct*); 132 | int(lame_set_athaa_sensitivity)(struct lame_global_struct*,float); 133 | int(lame_set_nogap_total)(struct lame_global_struct*,int); 134 | int(lame_set_nogap_currentindex)(struct lame_global_struct*,int); 135 | int(lame_set_VBR_hard_min)(struct lame_global_struct*,int); 136 | int(lame_get_RadioGain)(const struct lame_global_struct*); 137 | int(lame_set_force_short_blocks)(struct lame_global_struct*,int); 138 | float(lame_get_scale_right)(const struct lame_global_struct*); 139 | float(lame_get_scale_left)(const struct lame_global_struct*); 140 | int(lame_encode_buffer_interleaved_int)(struct lame_global_struct*,const int,const int,unsigned char*,const int); 141 | int(lame_get_experimentalX)(const struct lame_global_struct*); 142 | int(lame_set_VBR_q)(struct lame_global_struct*,int); 143 | int(lame_set_experimentalX)(struct lame_global_struct*,int); 144 | int(lame_set_emphasis)(struct lame_global_struct*,int); 145 | int(lame_set_decode_only)(struct lame_global_struct*,int); 146 | int(lame_set_copyright)(struct lame_global_struct*,int); 147 | int(lame_get_decode_only)(const struct lame_global_struct*); 148 | int(lame_set_highpassfreq)(struct lame_global_struct*,int); 149 | int(lame_set_mode)(struct lame_global_struct*,enum MPEG_mode_e); 150 | int(lame_get_emphasis)(const struct lame_global_struct*); 151 | int(lame_set_msgf)(struct lame_global_struct*,void(*unknown_2)(const char*,__builtin_va_list)); 152 | int(lame_get_findReplayGain)(const struct lame_global_struct*); 153 | int(lame_get_copyright)(const struct lame_global_struct*); 154 | int(lame_get_original)(const struct lame_global_struct*); 155 | int(lame_set_quality)(struct lame_global_struct*,int); 156 | int(lame_encode_buffer)(struct lame_global_struct*,const short,const short,const int,unsigned char*,const int); 157 | int(lame_get_experimentalY)(const struct lame_global_struct*); 158 | int(lame_get_experimentalZ)(const struct lame_global_struct*); 159 | int(lame_get_exp_nspsytune)(const struct lame_global_struct*); 160 | int(lame_set_useTemporal)(struct lame_global_struct*,int); 161 | unsigned long(lame_get_num_samples)(const struct lame_global_struct*); 162 | int(lame_get_bWriteVbrTag)(const struct lame_global_struct*); 163 | int(lame_set_interChRatio)(struct lame_global_struct*,float); 164 | int(lame_get_VBR_min_bitrate_kbps)(const struct lame_global_struct*); 165 | int(lame_set_VBR_max_bitrate_kbps)(struct lame_global_struct*,int); 166 | int(lame_get_free_format)(const struct lame_global_struct*); 167 | int(lame_set_lowpassfreq)(struct lame_global_struct*,int); 168 | int(lame_get_lowpasswidth)(const struct lame_global_struct*); 169 | int(lame_get_VBR_mean_bitrate_kbps)(const struct lame_global_struct*); 170 | int(lame_get_totalframes)(const struct lame_global_struct*); 171 | int(lame_get_maximum_number_of_samples)(struct lame_global_struct*,unsigned long); 172 | ]]) 173 | local CLIB = ffi.load(_G.FFI_LIB or "libmp3lame") 174 | local library = {} 175 | library = { 176 | Get_ATHlower = CLIB.lame_get_ATHlower, 177 | GetAthaaSensitivity = CLIB.lame_get_athaa_sensitivity, 178 | SetMsfix = CLIB.lame_set_msfix, 179 | GetDecodeOnTheFly = CLIB.lame_get_decode_on_the_fly, 180 | Set_ATHlower = CLIB.lame_set_ATHlower, 181 | GetNoATH = CLIB.lame_get_noATH, 182 | Get_ATHtype = CLIB.lame_get_ATHtype, 183 | SetDecodeOnTheFly = CLIB.lame_set_decode_on_the_fly, 184 | EncodeBufferIeeeFloat = CLIB.lame_encode_buffer_ieee_float, 185 | Set_ATHshort = CLIB.lame_set_ATHshort, 186 | Set_ATHtype = CLIB.lame_set_ATHtype, 187 | Init = CLIB.lame_init, 188 | SetScale = CLIB.lame_set_scale, 189 | Get_ATHshort = CLIB.lame_get_ATHshort, 190 | SetDebugf = CLIB.lame_set_debugf, 191 | GetSamplerate = CLIB.lame_get_samplerate, 192 | GetNoclipScale = CLIB.lame_get_noclipScale, 193 | GetInSamplerate = CLIB.lame_get_in_samplerate, 194 | SetInSamplerate = CLIB.lame_set_in_samplerate, 195 | Set_VBRMeanBitrateKbps = CLIB.lame_set_VBR_mean_bitrate_kbps, 196 | SetNumChannels = CLIB.lame_set_num_channels, 197 | GetNumChannels = CLIB.lame_get_num_channels, 198 | GetMsfix = CLIB.lame_get_msfix, 199 | GetBitrate = CLIB.lame_get_bitrate, 200 | GetInterChRatio = CLIB.lame_get_interChRatio, 201 | SetExtension = CLIB.lame_set_extension, 202 | SetFindReplayGain = CLIB.lame_set_findReplayGain, 203 | BitrateHist = CLIB.lame_bitrate_hist, 204 | GetExtension = CLIB.lame_get_extension, 205 | GetUseTemporal = CLIB.lame_get_useTemporal, 206 | GetVersion = CLIB.lame_get_version, 207 | SetPreset = CLIB.lame_set_preset, 208 | SetForceMs = CLIB.lame_set_force_ms, 209 | GetForceMs = CLIB.lame_get_force_ms, 210 | GetLowpassfreq = CLIB.lame_get_lowpassfreq, 211 | EncodeFlush = CLIB.lame_encode_flush, 212 | GetSizeMp3buffer = CLIB.lame_get_size_mp3buffer, 213 | SetHighpasswidth = CLIB.lame_set_highpasswidth, 214 | GetNoclipGainChange = CLIB.lame_get_noclipGainChange, 215 | Get_VBRMaxBitrateKbps = CLIB.lame_get_VBR_max_bitrate_kbps, 216 | Set_ATHonly = CLIB.lame_set_ATHonly, 217 | Set_VBR = CLIB.lame_set_VBR, 218 | GetHighpassfreq = CLIB.lame_get_highpassfreq, 219 | SetScaleRight = CLIB.lame_set_scale_right, 220 | Get_ATHonly = CLIB.lame_get_ATHonly, 221 | SetFreeFormat = CLIB.lame_set_free_format, 222 | SetExperimentalY = CLIB.lame_set_experimentalY, 223 | GetQuantComp = CLIB.lame_get_quant_comp, 224 | GetQuantCompShort = CLIB.lame_get_quant_comp_short, 225 | GetFramesize = CLIB.lame_get_framesize, 226 | SetQuantComp = CLIB.lame_set_quant_comp, 227 | EncodeBufferInt = CLIB.lame_encode_buffer_int, 228 | SetAllowDiffShort = CLIB.lame_set_allow_diff_short, 229 | SetQuantCompShort = CLIB.lame_set_quant_comp_short, 230 | GetMode = CLIB.lame_get_mode, 231 | GetAllowDiffShort = CLIB.lame_get_allow_diff_short, 232 | GetOutSamplerate = CLIB.lame_get_out_samplerate, 233 | BitrateStereoModeHist = CLIB.lame_bitrate_stereo_mode_hist, 234 | Get_VBRQ = CLIB.lame_get_VBR_q, 235 | SetNoATH = CLIB.lame_set_noATH, 236 | InitBitstream = CLIB.lame_init_bitstream, 237 | SetErrorProtection = CLIB.lame_set_error_protection, 238 | GetScale = CLIB.lame_get_scale, 239 | SetExpNspsytune = CLIB.lame_set_exp_nspsytune, 240 | SetLowpasswidth = CLIB.lame_set_lowpasswidth, 241 | Close = CLIB.lame_close, 242 | GetEncoderPadding = CLIB.lame_get_encoder_padding, 243 | Get_AudiophileGain = CLIB.lame_get_AudiophileGain, 244 | GetErrorProtection = CLIB.lame_get_error_protection, 245 | GetFrameNum = CLIB.lame_get_frameNum, 246 | GetEncoderDelay = CLIB.lame_get_encoder_delay, 247 | EncodeBufferIeeeDouble = CLIB.lame_encode_buffer_ieee_double, 248 | GetBrate = CLIB.lame_get_brate, 249 | Get_VBR = CLIB.lame_get_VBR, 250 | SetOriginal = CLIB.lame_set_original, 251 | GetStrict_ISO = CLIB.lame_get_strict_ISO, 252 | GetWriteId3tagAutomatic = CLIB.lame_get_write_id3tag_automatic, 253 | GetId3v2Tag = CLIB.lame_get_id3v2_tag, 254 | SetErrorf = CLIB.lame_set_errorf, 255 | EncodeFlushNogap = CLIB.lame_encode_flush_nogap, 256 | GetId3v1Tag = CLIB.lame_get_id3v1_tag, 257 | Get_PeakSample = CLIB.lame_get_PeakSample, 258 | SetNumSamples = CLIB.lame_set_num_samples, 259 | EncodeBufferLong = CLIB.lame_encode_buffer_long, 260 | SetCompressionRatio = CLIB.lame_set_compression_ratio, 261 | BitrateKbps = CLIB.lame_bitrate_kbps, 262 | Mp3TagsFid = CLIB.lame_mp3_tags_fid, 263 | Set_VBRQuality = CLIB.lame_set_VBR_quality, 264 | GetNoShortBlocks = CLIB.lame_get_no_short_blocks, 265 | BitrateBlockTypeHist = CLIB.lame_bitrate_block_type_hist, 266 | BlockTypeHist = CLIB.lame_block_type_hist, 267 | StereoModeHist = CLIB.lame_stereo_mode_hist, 268 | EncodeBufferLong2 = CLIB.lame_encode_buffer_long2, 269 | SetNoShortBlocks = CLIB.lame_set_no_short_blocks, 270 | Get_VBRQuality = CLIB.lame_get_VBR_quality, 271 | EncodeBufferInterleavedIeeeDouble = CLIB.lame_encode_buffer_interleaved_ieee_double, 272 | EncodeBufferInterleavedIeeeFloat = CLIB.lame_encode_buffer_interleaved_ieee_float, 273 | EncodeBufferFloat = CLIB.lame_encode_buffer_float, 274 | EncodeBufferInterleaved = CLIB.lame_encode_buffer_interleaved, 275 | SetDisableReservoir = CLIB.lame_set_disable_reservoir, 276 | PrintInternals = CLIB.lame_print_internals, 277 | GetQuality = CLIB.lame_get_quality, 278 | SetExperimentalZ = CLIB.lame_set_experimentalZ, 279 | PrintConfig = CLIB.lame_print_config, 280 | SetStrict_ISO = CLIB.lame_set_strict_ISO, 281 | GetMfSamplesToEncode = CLIB.lame_get_mf_samples_to_encode, 282 | GetAthaaType = CLIB.lame_get_athaa_type, 283 | InitParams = CLIB.lame_init_params, 284 | SetOutSamplerate = CLIB.lame_set_out_samplerate, 285 | GetDisableReservoir = CLIB.lame_get_disable_reservoir, 286 | GetForceShortBlocks = CLIB.lame_get_force_short_blocks, 287 | GetAnalysis = CLIB.lame_get_analysis, 288 | SetWriteId3tagAutomatic = CLIB.lame_set_write_id3tag_automatic, 289 | GetLametagFrame = CLIB.lame_get_lametag_frame, 290 | SetBWriteVbrTag = CLIB.lame_set_bWriteVbrTag, 291 | SetAthaaType = CLIB.lame_set_athaa_type, 292 | SetAsmOptimizations = CLIB.lame_set_asm_optimizations, 293 | SetAnalysis = CLIB.lame_set_analysis, 294 | SetScaleLeft = CLIB.lame_set_scale_left, 295 | GetNogapTotal = CLIB.lame_get_nogap_total, 296 | GetCompressionRatio = CLIB.lame_get_compression_ratio, 297 | Get_VBRHardMin = CLIB.lame_get_VBR_hard_min, 298 | GetHighpasswidth = CLIB.lame_get_highpasswidth, 299 | SetBrate = CLIB.lame_set_brate, 300 | Set_VBRMinBitrateKbps = CLIB.lame_set_VBR_min_bitrate_kbps, 301 | GetNogapCurrentindex = CLIB.lame_get_nogap_currentindex, 302 | SetAthaaSensitivity = CLIB.lame_set_athaa_sensitivity, 303 | SetNogapTotal = CLIB.lame_set_nogap_total, 304 | SetNogapCurrentindex = CLIB.lame_set_nogap_currentindex, 305 | Set_VBRHardMin = CLIB.lame_set_VBR_hard_min, 306 | Get_RadioGain = CLIB.lame_get_RadioGain, 307 | SetForceShortBlocks = CLIB.lame_set_force_short_blocks, 308 | GetScaleRight = CLIB.lame_get_scale_right, 309 | GetScaleLeft = CLIB.lame_get_scale_left, 310 | EncodeBufferInterleavedInt = CLIB.lame_encode_buffer_interleaved_int, 311 | GetExperimentalX = CLIB.lame_get_experimentalX, 312 | Set_VBRQ = CLIB.lame_set_VBR_q, 313 | SetExperimentalX = CLIB.lame_set_experimentalX, 314 | SetEmphasis = CLIB.lame_set_emphasis, 315 | SetDecodeOnly = CLIB.lame_set_decode_only, 316 | SetCopyright = CLIB.lame_set_copyright, 317 | GetDecodeOnly = CLIB.lame_get_decode_only, 318 | SetHighpassfreq = CLIB.lame_set_highpassfreq, 319 | SetMode = CLIB.lame_set_mode, 320 | GetEmphasis = CLIB.lame_get_emphasis, 321 | SetMsgf = CLIB.lame_set_msgf, 322 | GetFindReplayGain = CLIB.lame_get_findReplayGain, 323 | GetCopyright = CLIB.lame_get_copyright, 324 | GetOriginal = CLIB.lame_get_original, 325 | SetQuality = CLIB.lame_set_quality, 326 | EncodeBuffer = CLIB.lame_encode_buffer, 327 | GetExperimentalY = CLIB.lame_get_experimentalY, 328 | GetExperimentalZ = CLIB.lame_get_experimentalZ, 329 | GetExpNspsytune = CLIB.lame_get_exp_nspsytune, 330 | SetUseTemporal = CLIB.lame_set_useTemporal, 331 | GetNumSamples = CLIB.lame_get_num_samples, 332 | GetBWriteVbrTag = CLIB.lame_get_bWriteVbrTag, 333 | SetInterChRatio = CLIB.lame_set_interChRatio, 334 | Get_VBRMinBitrateKbps = CLIB.lame_get_VBR_min_bitrate_kbps, 335 | Set_VBRMaxBitrateKbps = CLIB.lame_set_VBR_max_bitrate_kbps, 336 | GetFreeFormat = CLIB.lame_get_free_format, 337 | SetLowpassfreq = CLIB.lame_set_lowpassfreq, 338 | GetLowpasswidth = CLIB.lame_get_lowpasswidth, 339 | Get_VBRMeanBitrateKbps = CLIB.lame_get_VBR_mean_bitrate_kbps, 340 | GetTotalframes = CLIB.lame_get_totalframes, 341 | GetMaximumNumberOfSamples = CLIB.lame_get_maximum_number_of_samples, 342 | } 343 | library.e = { 344 | OKAY = ffi.cast("enum lame_errorcodes_t", "LAME_OKAY"), 345 | NOERROR = ffi.cast("enum lame_errorcodes_t", "LAME_NOERROR"), 346 | GENERICERROR = ffi.cast("enum lame_errorcodes_t", "LAME_GENERICERROR"), 347 | NOMEM = ffi.cast("enum lame_errorcodes_t", "LAME_NOMEM"), 348 | BADBITRATE = ffi.cast("enum lame_errorcodes_t", "LAME_BADBITRATE"), 349 | BADSAMPFREQ = ffi.cast("enum lame_errorcodes_t", "LAME_BADSAMPFREQ"), 350 | INTERNALERROR = ffi.cast("enum lame_errorcodes_t", "LAME_INTERNALERROR"), 351 | } 352 | library.clib = CLIB 353 | return library 354 | -------------------------------------------------------------------------------- /libmp3lame/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /libsndfile/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | local header = ffibuild.NixBuild({ 5 | package_name = "libsndfile", 6 | library_name = "libsndfile", 7 | src = [[ 8 | #include "sndfile.h" 9 | ]]}) 10 | 11 | local meta_data = ffibuild.GetMetaData(header) 12 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^sf_") end, function(name) return name:find("^SF") end, true, true) 13 | 14 | do 15 | local extra = {} 16 | 17 | for name, struct in pairs(meta_data.structs) do 18 | if name:find("^struct SF_") and not header:find(name) then 19 | table.insert(extra, {str = name .. struct:GetDeclaration(meta_data) .. ";\n", pos = struct.i}) 20 | end 21 | end 22 | 23 | table.sort(extra, function(a, b) return a.pos < b.pos end) 24 | 25 | local str = "" 26 | 27 | for i,v in ipairs(extra) do 28 | str = str .. v.str 29 | end 30 | 31 | header = header .. str 32 | end 33 | 34 | local lua = ffibuild.StartLibrary(header) 35 | 36 | lua = lua .. "library = " .. meta_data:BuildFunctions("^sf_(.+)", "foo_bar", "FooBar") 37 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^SF[CMD]?_(.+)") 38 | 39 | ffibuild.EndLibrary(lua, header) -------------------------------------------------------------------------------- /libsndfile/libsndfile.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | ffi.cdef([[enum{SF_FORMAT_WAV=65536,SF_FORMAT_AIFF=131072,SF_FORMAT_AU=196608,SF_FORMAT_RAW=262144,SF_FORMAT_PAF=327680,SF_FORMAT_SVX=393216,SF_FORMAT_NIST=458752,SF_FORMAT_VOC=524288,SF_FORMAT_IRCAM=655360,SF_FORMAT_W64=720896,SF_FORMAT_MAT4=786432,SF_FORMAT_MAT5=851968,SF_FORMAT_PVF=917504,SF_FORMAT_XI=983040,SF_FORMAT_HTK=1048576,SF_FORMAT_SDS=1114112,SF_FORMAT_AVR=1179648,SF_FORMAT_WAVEX=1245184,SF_FORMAT_SD2=1441792,SF_FORMAT_FLAC=1507328,SF_FORMAT_CAF=1572864,SF_FORMAT_WVE=1638400,SF_FORMAT_OGG=2097152,SF_FORMAT_MPC2K=2162688,SF_FORMAT_RF64=2228224,SF_FORMAT_PCM_S8=1,SF_FORMAT_PCM_16=2,SF_FORMAT_PCM_24=3,SF_FORMAT_PCM_32=4,SF_FORMAT_PCM_U8=5,SF_FORMAT_FLOAT=6,SF_FORMAT_DOUBLE=7,SF_FORMAT_ULAW=16,SF_FORMAT_ALAW=17,SF_FORMAT_IMA_ADPCM=18,SF_FORMAT_MS_ADPCM=19,SF_FORMAT_GSM610=32,SF_FORMAT_VOX_ADPCM=33,SF_FORMAT_G721_32=48,SF_FORMAT_G723_24=49,SF_FORMAT_G723_40=50,SF_FORMAT_DWVW_12=64,SF_FORMAT_DWVW_16=65,SF_FORMAT_DWVW_24=66,SF_FORMAT_DWVW_N=67,SF_FORMAT_DPCM_8=80,SF_FORMAT_DPCM_16=81,SF_FORMAT_VORBIS=96,SF_FORMAT_ALAC_16=112,SF_FORMAT_ALAC_20=113,SF_FORMAT_ALAC_24=114,SF_FORMAT_ALAC_32=115,SF_ENDIAN_FILE=0,SF_ENDIAN_LITTLE=268435456,SF_ENDIAN_BIG=536870912,SF_ENDIAN_CPU=805306368,SF_FORMAT_SUBMASK=65535,SF_FORMAT_TYPEMASK=268369920,SF_FORMAT_ENDMASK=805306368, 3 | SFC_GET_LIB_VERSION=4096,SFC_GET_LOG_INFO=4097,SFC_GET_CURRENT_SF_INFO=4098,SFC_GET_NORM_DOUBLE=4112,SFC_GET_NORM_FLOAT=4113,SFC_SET_NORM_DOUBLE=4114,SFC_SET_NORM_FLOAT=4115,SFC_SET_SCALE_FLOAT_INT_READ=4116,SFC_SET_SCALE_INT_FLOAT_WRITE=4117,SFC_GET_SIMPLE_FORMAT_COUNT=4128,SFC_GET_SIMPLE_FORMAT=4129,SFC_GET_FORMAT_INFO=4136,SFC_GET_FORMAT_MAJOR_COUNT=4144,SFC_GET_FORMAT_MAJOR=4145,SFC_GET_FORMAT_SUBTYPE_COUNT=4146,SFC_GET_FORMAT_SUBTYPE=4147,SFC_CALC_SIGNAL_MAX=4160,SFC_CALC_NORM_SIGNAL_MAX=4161,SFC_CALC_MAX_ALL_CHANNELS=4162,SFC_CALC_NORM_MAX_ALL_CHANNELS=4163,SFC_GET_SIGNAL_MAX=4164,SFC_GET_MAX_ALL_CHANNELS=4165,SFC_SET_ADD_PEAK_CHUNK=4176,SFC_SET_ADD_HEADER_PAD_CHUNK=4177,SFC_UPDATE_HEADER_NOW=4192,SFC_SET_UPDATE_HEADER_AUTO=4193,SFC_FILE_TRUNCATE=4224,SFC_SET_RAW_START_OFFSET=4240,SFC_SET_DITHER_ON_WRITE=4256,SFC_SET_DITHER_ON_READ=4257,SFC_GET_DITHER_INFO_COUNT=4258,SFC_GET_DITHER_INFO=4259,SFC_GET_EMBED_FILE_INFO=4272,SFC_SET_CLIPPING=4288,SFC_GET_CLIPPING=4289,SFC_GET_CUE_COUNT=4301,SFC_GET_CUE=4302,SFC_SET_CUE=4303,SFC_GET_INSTRUMENT=4304,SFC_SET_INSTRUMENT=4305,SFC_GET_LOOP_INFO=4320,SFC_GET_BROADCAST_INFO=4336,SFC_SET_BROADCAST_INFO=4337,SFC_GET_CHANNEL_MAP_INFO=4352,SFC_SET_CHANNEL_MAP_INFO=4353,SFC_RAW_DATA_NEEDS_ENDSWAP=4368,SFC_WAVEX_SET_AMBISONIC=4608,SFC_WAVEX_GET_AMBISONIC=4609,SFC_RF64_AUTO_DOWNGRADE=4624,SFC_SET_VBR_ENCODING_QUALITY=4864,SFC_SET_COMPRESSION_LEVEL=4865,SFC_SET_CART_INFO=5120,SFC_GET_CART_INFO=5121,SFC_TEST_IEEE_FLOAT_REPLACE=24577,SFC_SET_ADD_DITHER_ON_WRITE=4208,SFC_SET_ADD_DITHER_ON_READ=4209, 4 | SF_STR_TITLE=1,SF_STR_COPYRIGHT=2,SF_STR_SOFTWARE=3,SF_STR_ARTIST=4,SF_STR_COMMENT=5,SF_STR_DATE=6,SF_STR_ALBUM=7,SF_STR_LICENSE=8,SF_STR_TRACKNUMBER=9,SF_STR_GENRE=16, 5 | SF_FALSE=0,SF_TRUE=1,SFM_READ=16,SFM_WRITE=32,SFM_RDWR=48,SF_AMBISONIC_NONE=64,SF_AMBISONIC_B_FORMAT=65, 6 | SF_ERR_NO_ERROR=0,SF_ERR_UNRECOGNISED_FORMAT=1,SF_ERR_SYSTEM=2,SF_ERR_MALFORMED_FILE=3,SF_ERR_UNSUPPORTED_ENCODING=4, 7 | SF_CHANNEL_MAP_INVALID=0,SF_CHANNEL_MAP_MONO=1,SF_CHANNEL_MAP_LEFT=2,SF_CHANNEL_MAP_RIGHT=3,SF_CHANNEL_MAP_CENTER=4,SF_CHANNEL_MAP_FRONT_LEFT=5,SF_CHANNEL_MAP_FRONT_RIGHT=6,SF_CHANNEL_MAP_FRONT_CENTER=7,SF_CHANNEL_MAP_REAR_CENTER=8,SF_CHANNEL_MAP_REAR_LEFT=9,SF_CHANNEL_MAP_REAR_RIGHT=10,SF_CHANNEL_MAP_LFE=11,SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER=12,SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER=13,SF_CHANNEL_MAP_SIDE_LEFT=14,SF_CHANNEL_MAP_SIDE_RIGHT=15,SF_CHANNEL_MAP_TOP_CENTER=16,SF_CHANNEL_MAP_TOP_FRONT_LEFT=17,SF_CHANNEL_MAP_TOP_FRONT_RIGHT=18,SF_CHANNEL_MAP_TOP_FRONT_CENTER=19,SF_CHANNEL_MAP_TOP_REAR_LEFT=20,SF_CHANNEL_MAP_TOP_REAR_RIGHT=21,SF_CHANNEL_MAP_TOP_REAR_CENTER=22,SF_CHANNEL_MAP_AMBISONIC_B_W=23,SF_CHANNEL_MAP_AMBISONIC_B_X=24,SF_CHANNEL_MAP_AMBISONIC_B_Y=25,SF_CHANNEL_MAP_AMBISONIC_B_Z=26,SF_CHANNEL_MAP_MAX=27, 8 | SFD_DEFAULT_LEVEL=0,SFD_CUSTOM_LEVEL=1073741824,SFD_NO_DITHER=500,SFD_WHITE=501,SFD_TRIANGULAR_PDF=502, 9 | SF_LOOP_NONE=800,SF_LOOP_FORWARD=801,SF_LOOP_BACKWARD=802,SF_LOOP_ALTERNATING=803, 10 | SF_SEEK_SET=0,SF_SEEK_CUR=1,SF_SEEK_END=2,};struct SNDFILE_tag {}; 11 | struct SF_INFO {signed long frames;int samplerate;int channels;int format;int sections;int seekable;}; 12 | struct SF_VIRTUAL_IO {signed long(*get_filelen)(void*);signed long(*seek)(signed long,int,void*);signed long(*read)(void*,signed long,void*);signed long(*write)(const void*,signed long,void*);signed long(*tell)(void*);}; 13 | struct SF_CHUNK_INFO {char id[64];unsigned int id_size;unsigned int datalen;void*data;}; 14 | struct SF_CHUNK_ITERATOR {}; 15 | struct SNDFILE_tag*(sf_open_virtual)(struct SF_VIRTUAL_IO*,int,struct SF_INFO*,void*); 16 | int(sf_get_chunk_data)(const struct SF_CHUNK_ITERATOR*,struct SF_CHUNK_INFO*); 17 | int(sf_format_check)(const struct SF_INFO*); 18 | signed long(sf_readf_float)(struct SNDFILE_tag*,float*,signed long); 19 | struct SF_CHUNK_ITERATOR*(sf_next_chunk_iterator)(struct SF_CHUNK_ITERATOR*); 20 | struct SNDFILE_tag*(sf_open)(const char*,int,struct SF_INFO*); 21 | int(sf_set_chunk)(struct SNDFILE_tag*,const struct SF_CHUNK_INFO*); 22 | signed long(sf_readf_double)(struct SNDFILE_tag*,double*,signed long); 23 | signed long(sf_write_float)(struct SNDFILE_tag*,const float*,signed long); 24 | signed long(sf_read_short)(struct SNDFILE_tag*,short*,signed long); 25 | const char*(sf_version_string)(); 26 | int(sf_set_string)(struct SNDFILE_tag*,int,const char*); 27 | int(sf_error_str)(struct SNDFILE_tag*,char*,unsigned long); 28 | const char*(sf_error_number)(int); 29 | const char*(sf_get_string)(struct SNDFILE_tag*,int); 30 | signed long(sf_writef_int)(struct SNDFILE_tag*,const int*,signed long); 31 | signed long(sf_write_raw)(struct SNDFILE_tag*,const void*,signed long); 32 | int(sf_get_chunk_size)(const struct SF_CHUNK_ITERATOR*,struct SF_CHUNK_INFO*); 33 | signed long(sf_write_short)(struct SNDFILE_tag*,const short*,signed long); 34 | void(sf_write_sync)(struct SNDFILE_tag*); 35 | int(sf_close)(struct SNDFILE_tag*); 36 | signed long(sf_write_double)(struct SNDFILE_tag*,const double*,signed long); 37 | signed long(sf_read_double)(struct SNDFILE_tag*,double*,signed long); 38 | signed long(sf_read_float)(struct SNDFILE_tag*,float*,signed long); 39 | signed long(sf_write_int)(struct SNDFILE_tag*,const int*,signed long); 40 | signed long(sf_read_int)(struct SNDFILE_tag*,int*,signed long); 41 | struct SF_CHUNK_ITERATOR*(sf_get_chunk_iterator)(struct SNDFILE_tag*,const struct SF_CHUNK_INFO*); 42 | signed long(sf_read_raw)(struct SNDFILE_tag*,void*,signed long); 43 | signed long(sf_writef_double)(struct SNDFILE_tag*,const double*,signed long); 44 | signed long(sf_writef_float)(struct SNDFILE_tag*,const float*,signed long); 45 | signed long(sf_readf_int)(struct SNDFILE_tag*,int*,signed long); 46 | signed long(sf_writef_short)(struct SNDFILE_tag*,const short*,signed long); 47 | signed long(sf_readf_short)(struct SNDFILE_tag*,short*,signed long); 48 | int(sf_current_byterate)(struct SNDFILE_tag*); 49 | signed long(sf_seek)(struct SNDFILE_tag*,signed long,int); 50 | int(sf_command)(struct SNDFILE_tag*,int,void*,int); 51 | struct SNDFILE_tag*(sf_open_fd)(int,int,struct SF_INFO*,int); 52 | const char*(sf_strerror)(struct SNDFILE_tag*); 53 | int(sf_perror)(struct SNDFILE_tag*); 54 | int(sf_error)(struct SNDFILE_tag*); 55 | struct SF_FORMAT_INFO { int format ; const char * name ; const char * extension ; }; 56 | struct SF_DITHER_INFO { int type ; double level ; const char * name ; }; 57 | struct SF_EMBED_FILE_INFO { signed long offset ; signed long length ; }; 58 | struct SF_CUE_POINT { signed int indx ; unsigned int position ; signed int fcc_chunk ; signed int chunk_start ; signed int block_start ; unsigned int sample_offset ; char name[ 256 ] ; }; 59 | struct SF_CUES { unsigned int cue_count ; struct SF_CUE_POINT cue_points[ 100 ] ; }; 60 | struct SF_INSTRUMENT { int gain ; char basenote ; char detune ; char velocity_lo ; char velocity_hi ; char key_lo ; char key_hi ; int loop_count ; struct { int mode ; unsigned int start ; unsigned int end ; unsigned int count ; } loops [ 16 ] ; }; 61 | struct SF_LOOP_INFO { short time_sig_num ; short time_sig_den ; int loop_mode ; int num_beats ; float bpm ; int root_key ; int future[ 6 ] ; }; 62 | struct SF_BROADCAST_INFO { char description[ 256 ] ; char originator[ 32 ] ; char originator_reference[ 32 ] ; char origination_date[ 10 ] ; char origination_time[ 8 ] ; unsigned int time_reference_low ; unsigned int time_reference_high ; short version ; char umid[ 64 ] ; char reserved[ 190 ] ; unsigned int coding_history_size ; char coding_history[ 256 ] ; }; 63 | struct SF_CART_TIMER { char usage[ 4 ] ; signed int value ; }; 64 | struct SF_CART_INFO { char version[ 4 ] ; char title[ 64 ] ; char artist[ 64 ] ; char cut_id[ 64 ] ; char client_id[ 64 ] ; char category[ 64 ] ; char classification[ 64 ] ; char out_cue[ 64 ] ; char start_date[ 10 ] ; char start_time[ 8 ] ; char end_date[ 10 ] ; char end_time[ 8 ] ; char producer_app_id[ 64 ] ; char producer_app_version[ 64 ] ; char user_def[ 64 ] ; signed int level_reference ; struct SF_CART_TIMER post_timers[ 8 ] ; char reserved[ 276 ] ; char url[ 1024 ] ; unsigned int tag_text_size ; char tag_text[ 256 ] ; }; 65 | ]]) 66 | local CLIB = ffi.load(_G.FFI_LIB or "libsndfile") 67 | local library = {} 68 | library = { 69 | OpenVirtual = CLIB.sf_open_virtual, 70 | GetChunkData = CLIB.sf_get_chunk_data, 71 | FormatCheck = CLIB.sf_format_check, 72 | ReadfFloat = CLIB.sf_readf_float, 73 | NextChunkIterator = CLIB.sf_next_chunk_iterator, 74 | Open = CLIB.sf_open, 75 | SetChunk = CLIB.sf_set_chunk, 76 | ReadfDouble = CLIB.sf_readf_double, 77 | WriteFloat = CLIB.sf_write_float, 78 | ReadShort = CLIB.sf_read_short, 79 | VersionString = CLIB.sf_version_string, 80 | SetString = CLIB.sf_set_string, 81 | ErrorStr = CLIB.sf_error_str, 82 | ErrorNumber = CLIB.sf_error_number, 83 | GetString = CLIB.sf_get_string, 84 | WritefInt = CLIB.sf_writef_int, 85 | WriteRaw = CLIB.sf_write_raw, 86 | GetChunkSize = CLIB.sf_get_chunk_size, 87 | WriteShort = CLIB.sf_write_short, 88 | WriteSync = CLIB.sf_write_sync, 89 | Close = CLIB.sf_close, 90 | WriteDouble = CLIB.sf_write_double, 91 | ReadDouble = CLIB.sf_read_double, 92 | ReadFloat = CLIB.sf_read_float, 93 | WriteInt = CLIB.sf_write_int, 94 | ReadInt = CLIB.sf_read_int, 95 | GetChunkIterator = CLIB.sf_get_chunk_iterator, 96 | ReadRaw = CLIB.sf_read_raw, 97 | WritefDouble = CLIB.sf_writef_double, 98 | WritefFloat = CLIB.sf_writef_float, 99 | ReadfInt = CLIB.sf_readf_int, 100 | WritefShort = CLIB.sf_writef_short, 101 | ReadfShort = CLIB.sf_readf_short, 102 | CurrentByterate = CLIB.sf_current_byterate, 103 | Seek = CLIB.sf_seek, 104 | Command = CLIB.sf_command, 105 | OpenFd = CLIB.sf_open_fd, 106 | Strerror = CLIB.sf_strerror, 107 | Perror = CLIB.sf_perror, 108 | Error = CLIB.sf_error, 109 | } 110 | library.e = { 111 | FORMAT_WAV = 65536, 112 | FORMAT_AIFF = 131072, 113 | FORMAT_AU = 196608, 114 | FORMAT_RAW = 262144, 115 | FORMAT_PAF = 327680, 116 | FORMAT_SVX = 393216, 117 | FORMAT_NIST = 458752, 118 | FORMAT_VOC = 524288, 119 | FORMAT_IRCAM = 655360, 120 | FORMAT_W64 = 720896, 121 | FORMAT_MAT4 = 786432, 122 | FORMAT_MAT5 = 851968, 123 | FORMAT_PVF = 917504, 124 | FORMAT_XI = 983040, 125 | FORMAT_HTK = 1048576, 126 | FORMAT_SDS = 1114112, 127 | FORMAT_AVR = 1179648, 128 | FORMAT_WAVEX = 1245184, 129 | FORMAT_SD2 = 1441792, 130 | FORMAT_FLAC = 1507328, 131 | FORMAT_CAF = 1572864, 132 | FORMAT_WVE = 1638400, 133 | FORMAT_OGG = 2097152, 134 | FORMAT_MPC2K = 2162688, 135 | FORMAT_RF64 = 2228224, 136 | FORMAT_PCM_S8 = 1, 137 | FORMAT_PCM_16 = 2, 138 | FORMAT_PCM_24 = 3, 139 | FORMAT_PCM_32 = 4, 140 | FORMAT_PCM_U8 = 5, 141 | FORMAT_FLOAT = 6, 142 | FORMAT_DOUBLE = 7, 143 | FORMAT_ULAW = 16, 144 | FORMAT_ALAW = 17, 145 | FORMAT_IMA_ADPCM = 18, 146 | FORMAT_MS_ADPCM = 19, 147 | FORMAT_GSM610 = 32, 148 | FORMAT_VOX_ADPCM = 33, 149 | FORMAT_G721_32 = 48, 150 | FORMAT_G723_24 = 49, 151 | FORMAT_G723_40 = 50, 152 | FORMAT_DWVW_12 = 64, 153 | FORMAT_DWVW_16 = 65, 154 | FORMAT_DWVW_24 = 66, 155 | FORMAT_DWVW_N = 67, 156 | FORMAT_DPCM_8 = 80, 157 | FORMAT_DPCM_16 = 81, 158 | FORMAT_VORBIS = 96, 159 | FORMAT_ALAC_16 = 112, 160 | FORMAT_ALAC_20 = 113, 161 | FORMAT_ALAC_24 = 114, 162 | FORMAT_ALAC_32 = 115, 163 | ENDIAN_FILE = 0, 164 | ENDIAN_LITTLE = 268435456, 165 | ENDIAN_BIG = 536870912, 166 | ENDIAN_CPU = 805306368, 167 | FORMAT_SUBMASK = 65535, 168 | FORMAT_TYPEMASK = 268369920, 169 | FORMAT_ENDMASK = 805306368, 170 | GET_LIB_VERSION = 4096, 171 | GET_LOG_INFO = 4097, 172 | GET_CURRENT_SF_INFO = 4098, 173 | GET_NORM_DOUBLE = 4112, 174 | GET_NORM_FLOAT = 4113, 175 | SET_NORM_DOUBLE = 4114, 176 | SET_NORM_FLOAT = 4115, 177 | SET_SCALE_FLOAT_INT_READ = 4116, 178 | SET_SCALE_INT_FLOAT_WRITE = 4117, 179 | GET_SIMPLE_FORMAT_COUNT = 4128, 180 | GET_SIMPLE_FORMAT = 4129, 181 | GET_FORMAT_INFO = 4136, 182 | GET_FORMAT_MAJOR_COUNT = 4144, 183 | GET_FORMAT_MAJOR = 4145, 184 | GET_FORMAT_SUBTYPE_COUNT = 4146, 185 | GET_FORMAT_SUBTYPE = 4147, 186 | CALC_SIGNAL_MAX = 4160, 187 | CALC_NORM_SIGNAL_MAX = 4161, 188 | CALC_MAX_ALL_CHANNELS = 4162, 189 | CALC_NORM_MAX_ALL_CHANNELS = 4163, 190 | GET_SIGNAL_MAX = 4164, 191 | GET_MAX_ALL_CHANNELS = 4165, 192 | SET_ADD_PEAK_CHUNK = 4176, 193 | SET_ADD_HEADER_PAD_CHUNK = 4177, 194 | UPDATE_HEADER_NOW = 4192, 195 | SET_UPDATE_HEADER_AUTO = 4193, 196 | FILE_TRUNCATE = 4224, 197 | SET_RAW_START_OFFSET = 4240, 198 | SET_DITHER_ON_WRITE = 4256, 199 | SET_DITHER_ON_READ = 4257, 200 | GET_DITHER_INFO_COUNT = 4258, 201 | GET_DITHER_INFO = 4259, 202 | GET_EMBED_FILE_INFO = 4272, 203 | SET_CLIPPING = 4288, 204 | GET_CLIPPING = 4289, 205 | GET_CUE_COUNT = 4301, 206 | GET_CUE = 4302, 207 | SET_CUE = 4303, 208 | GET_INSTRUMENT = 4304, 209 | SET_INSTRUMENT = 4305, 210 | GET_LOOP_INFO = 4320, 211 | GET_BROADCAST_INFO = 4336, 212 | SET_BROADCAST_INFO = 4337, 213 | GET_CHANNEL_MAP_INFO = 4352, 214 | SET_CHANNEL_MAP_INFO = 4353, 215 | RAW_DATA_NEEDS_ENDSWAP = 4368, 216 | WAVEX_SET_AMBISONIC = 4608, 217 | WAVEX_GET_AMBISONIC = 4609, 218 | RF64_AUTO_DOWNGRADE = 4624, 219 | SET_VBR_ENCODING_QUALITY = 4864, 220 | SET_COMPRESSION_LEVEL = 4865, 221 | SET_CART_INFO = 5120, 222 | GET_CART_INFO = 5121, 223 | TEST_IEEE_FLOAT_REPLACE = 24577, 224 | SET_ADD_DITHER_ON_WRITE = 4208, 225 | SET_ADD_DITHER_ON_READ = 4209, 226 | STR_TITLE = 1, 227 | STR_COPYRIGHT = 2, 228 | STR_SOFTWARE = 3, 229 | STR_ARTIST = 4, 230 | STR_COMMENT = 5, 231 | STR_DATE = 6, 232 | STR_ALBUM = 7, 233 | STR_LICENSE = 8, 234 | STR_TRACKNUMBER = 9, 235 | STR_GENRE = 16, 236 | FALSE = 0, 237 | TRUE = 1, 238 | READ = 16, 239 | WRITE = 32, 240 | RDWR = 48, 241 | AMBISONIC_NONE = 64, 242 | AMBISONIC_B_FORMAT = 65, 243 | ERR_NO_ERROR = 0, 244 | ERR_UNRECOGNISED_FORMAT = 1, 245 | ERR_SYSTEM = 2, 246 | ERR_MALFORMED_FILE = 3, 247 | ERR_UNSUPPORTED_ENCODING = 4, 248 | CHANNEL_MAP_INVALID = 0, 249 | CHANNEL_MAP_MONO = 1, 250 | CHANNEL_MAP_LEFT = 2, 251 | CHANNEL_MAP_RIGHT = 3, 252 | CHANNEL_MAP_CENTER = 4, 253 | CHANNEL_MAP_FRONT_LEFT = 5, 254 | CHANNEL_MAP_FRONT_RIGHT = 6, 255 | CHANNEL_MAP_FRONT_CENTER = 7, 256 | CHANNEL_MAP_REAR_CENTER = 8, 257 | CHANNEL_MAP_REAR_LEFT = 9, 258 | CHANNEL_MAP_REAR_RIGHT = 10, 259 | CHANNEL_MAP_LFE = 11, 260 | CHANNEL_MAP_FRONT_LEFT_OF_CENTER = 12, 261 | CHANNEL_MAP_FRONT_RIGHT_OF_CENTER = 13, 262 | CHANNEL_MAP_SIDE_LEFT = 14, 263 | CHANNEL_MAP_SIDE_RIGHT = 15, 264 | CHANNEL_MAP_TOP_CENTER = 16, 265 | CHANNEL_MAP_TOP_FRONT_LEFT = 17, 266 | CHANNEL_MAP_TOP_FRONT_RIGHT = 18, 267 | CHANNEL_MAP_TOP_FRONT_CENTER = 19, 268 | CHANNEL_MAP_TOP_REAR_LEFT = 20, 269 | CHANNEL_MAP_TOP_REAR_RIGHT = 21, 270 | CHANNEL_MAP_TOP_REAR_CENTER = 22, 271 | CHANNEL_MAP_AMBISONIC_B_W = 23, 272 | CHANNEL_MAP_AMBISONIC_B_X = 24, 273 | CHANNEL_MAP_AMBISONIC_B_Y = 25, 274 | CHANNEL_MAP_AMBISONIC_B_Z = 26, 275 | CHANNEL_MAP_MAX = 27, 276 | DEFAULT_LEVEL = 0, 277 | CUSTOM_LEVEL = 1073741824, 278 | NO_DITHER = 500, 279 | WHITE = 501, 280 | TRIANGULAR_PDF = 502, 281 | LOOP_NONE = 800, 282 | LOOP_FORWARD = 801, 283 | LOOP_BACKWARD = 802, 284 | LOOP_ALTERNATING = 803, 285 | SEEK_SET = 0, 286 | SEEK_CUR = 1, 287 | SEEK_END = 2, 288 | } 289 | library.clib = CLIB 290 | return library 291 | -------------------------------------------------------------------------------- /libsndfile/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /luajit/Makefile: -------------------------------------------------------------------------------- 1 | LUA_URL = https://github.com/LuaJIT/LuaJIT repo 2 | LUA_BRANCH = v2.1 3 | 4 | LUA_DIR = ../luajit/ 5 | LUA_BIN = $(LUA_DIR)repo/src/luajit 6 | 7 | all: repo 8 | export LD_LIBRARY_PATH=".:$LD_LIBRARY_PATH" && ./$(LUA_BIN) build.lua 9 | repo: 10 | git clone $(LUA_URL) 11 | cd repo; git checkout $(LUA_BRANCH) 12 | cd repo; make XCFLAGS+=-fPIC XCFLAGS+=-DLUAJIT_ENABLE_GC64 XCFLAGS+=-DLUAJIT_ENABLE_LUA52COMPAT; 13 | 14 | clean: 15 | rm -rf repo 16 | -------------------------------------------------------------------------------- /luajit/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | -------------------------------------------------------------------------------- /luajit/luajit.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | ffi.cdef([[struct lua_State {}; 3 | struct lua_Debug {int event;const char*name;const char*namewhat;const char*what;const char*source;int currentline;int nups;int linedefined;int lastlinedefined;char short_src[60];int i_ci;}; 4 | struct luaL_Reg {const char*name;int(*func)(struct lua_State*);}; 5 | struct luaL_Buffer {char*p;int lvl;struct lua_State*L;}; 6 | void(luaL_buffinit)(struct lua_State*,struct luaL_Buffer*); 7 | void(lua_setfield)(struct lua_State*,int,const char*); 8 | double(luaL_optnumber)(struct lua_State*,int,double); 9 | void(lua_xmove)(struct lua_State*,struct lua_State*,int); 10 | void(luaL_pushresult)(struct luaL_Buffer*); 11 | struct lua_State*(lua_newstate)(void*(*f)(void*,void*,unsigned long,unsigned long),void*); 12 | void(luaL_addstring)(struct luaL_Buffer*,const char*); 13 | int(lua_cpcall)(struct lua_State*,int(*func)(struct lua_State*),void*); 14 | int(lua_status)(struct lua_State*); 15 | void(lua_pushboolean)(struct lua_State*,int); 16 | int(luaL_loadbuffer)(struct lua_State*,const char*,unsigned long,const char*); 17 | void(lua_replace)(struct lua_State*,int); 18 | const char*(lua_pushfstring)(struct lua_State*,const char*,...); 19 | char*(luaL_prepbuffer)(struct luaL_Buffer*); 20 | void(luaL_setmetatable)(struct lua_State*,const char*); 21 | const char*(lua_getlocal)(struct lua_State*,const struct lua_Debug*,int); 22 | void(luaL_checktype)(struct lua_State*,int,int); 23 | void(luaL_pushmodule)(struct lua_State*,const char*,int); 24 | int(lua_gettop)(struct lua_State*); 25 | void(lua_remove)(struct lua_State*,int); 26 | void(luaL_unref)(struct lua_State*,int,int); 27 | int(lua_sethook)(struct lua_State*,void(*func)(struct lua_State*,struct lua_Debug*),int,int); 28 | void(luaL_traceback)(struct lua_State*,struct lua_State*,const char*,int); 29 | struct lua_State*(lua_tothread)(struct lua_State*,int); 30 | int(luaL_loadfilex)(struct lua_State*,const char*,const char*); 31 | int(luaL_ref)(struct lua_State*,int); 32 | void(lua_setallocf)(struct lua_State*,void*(*f)(void*,void*,unsigned long,unsigned long),void*); 33 | int(luaL_callmeta)(struct lua_State*,int,const char*); 34 | int(luaL_execresult)(struct lua_State*,int); 35 | int(lua_gethookmask)(struct lua_State*); 36 | int(luaL_loadstring)(struct lua_State*,const char*); 37 | void(lua_pushnumber)(struct lua_State*,double); 38 | double(luaL_checknumber)(struct lua_State*,int); 39 | void(lua_pushvalue)(struct lua_State*,int); 40 | int(lua_resume)(struct lua_State*,int); 41 | void(lua_pushlstring)(struct lua_State*,const char*,unsigned long); 42 | const char*(luaL_gsub)(struct lua_State*,const char*,const char*,const char*); 43 | void(lua_close)(struct lua_State*); 44 | int(lua_checkstack)(struct lua_State*,int); 45 | int(luaopen_table)(struct lua_State*); 46 | int(luaL_error)(struct lua_State*,const char*,...); 47 | void(luaL_where)(struct lua_State*,int); 48 | long(luaL_optinteger)(struct lua_State*,int,long); 49 | int(luaopen_debug)(struct lua_State*); 50 | int(lua_dump)(struct lua_State*,int(*writer)(struct lua_State*,const void*,unsigned long,void*),void*); 51 | void(*lua_gethook(struct lua_State*))(struct lua_State*,struct lua_Debug*); 52 | void(luaL_checkany)(struct lua_State*,int); 53 | void*(luaL_testudata)(struct lua_State*,int,const char*); 54 | long(lua_tointegerx)(struct lua_State*,int,int*); 55 | int(lua_type)(struct lua_State*,int); 56 | int(lua_setmetatable)(struct lua_State*,int); 57 | void(luaL_checkstack)(struct lua_State*,int,const char*); 58 | void(lua_rawseti)(struct lua_State*,int,int); 59 | const char*(lua_setlocal)(struct lua_State*,const struct lua_Debug*,int); 60 | long(luaL_checkinteger)(struct lua_State*,int); 61 | const char*(luaL_optlstring)(struct lua_State*,int,const char*,unsigned long*); 62 | int(lua_isstring)(struct lua_State*,int); 63 | double(lua_tonumberx)(struct lua_State*,int,int*); 64 | void(lua_setlevel)(struct lua_State*,struct lua_State*); 65 | int(luaL_typerror)(struct lua_State*,int,const char*); 66 | const char*(luaL_findtable)(struct lua_State*,int,const char*,int); 67 | int(luaL_getmetafield)(struct lua_State*,int,const char*); 68 | void(luaL_register)(struct lua_State*,const char*,const struct luaL_Reg*); 69 | void(lua_pushstring)(struct lua_State*,const char*); 70 | struct lua_State*(luaL_newstate)(); 71 | void(lua_rawset)(struct lua_State*,int); 72 | void(lua_pushcclosure)(struct lua_State*,int(*fn)(struct lua_State*),int); 73 | int(lua_loadx)(struct lua_State*,const char*(*reader)(struct lua_State*,void*,unsigned long*),void*,const char*,const char*); 74 | void(luaL_addlstring)(struct luaL_Buffer*,const char*,unsigned long); 75 | int(luaL_loadbufferx)(struct lua_State*,const char*,unsigned long,const char*,const char*); 76 | unsigned long(lua_objlen)(struct lua_State*,int); 77 | int(lua_gc)(struct lua_State*,int,int); 78 | int(*lua_atpanic(struct lua_State*,int(*panicf)(struct lua_State*)))(struct lua_State*); 79 | int(luaL_argerror)(struct lua_State*,int,const char*); 80 | const char*(lua_typename)(struct lua_State*,int); 81 | int(luaL_loadfile)(struct lua_State*,const char*); 82 | int(luaopen_io)(struct lua_State*); 83 | void(lua_createtable)(struct lua_State*,int,int); 84 | void*(lua_newuserdata)(struct lua_State*,unsigned long); 85 | int(lua_pcall)(struct lua_State*,int,int,int); 86 | int(lua_lessthan)(struct lua_State*,int,int); 87 | int(lua_pushthread)(struct lua_State*); 88 | const void*(lua_topointer)(struct lua_State*,int); 89 | int(lua_error)(struct lua_State*); 90 | int(lua_isyieldable)(struct lua_State*); 91 | int(luaopen_package)(struct lua_State*); 92 | int(lua_rawequal)(struct lua_State*,int,int); 93 | const double*(lua_version)(struct lua_State*); 94 | const char*(lua_getupvalue)(struct lua_State*,int,int); 95 | void*(luaL_checkudata)(struct lua_State*,int,const char*); 96 | void(lua_rawget)(struct lua_State*,int); 97 | void(lua_pushnil)(struct lua_State*); 98 | void(luaL_openlibs)(struct lua_State*); 99 | const char*(lua_pushvfstring)(struct lua_State*,const char*,__builtin_va_list); 100 | void(lua_rawgeti)(struct lua_State*,int,int); 101 | int(lua_toboolean)(struct lua_State*,int); 102 | void(lua_concat)(struct lua_State*,int); 103 | int(lua_getmetatable)(struct lua_State*,int); 104 | struct lua_State*(lua_newthread)(struct lua_State*); 105 | void(luaL_setfuncs)(struct lua_State*,const struct luaL_Reg*,int); 106 | int(lua_yield)(struct lua_State*,int); 107 | void*(lua_upvalueid)(struct lua_State*,int,int); 108 | void*(lua_touserdata)(struct lua_State*,int); 109 | void(luaL_addvalue)(struct luaL_Buffer*); 110 | void(lua_settop)(struct lua_State*,int); 111 | int(luaopen_jit)(struct lua_State*); 112 | void(lua_getfenv)(struct lua_State*,int); 113 | long(lua_tointeger)(struct lua_State*,int); 114 | const char*(lua_tolstring)(struct lua_State*,int,unsigned long*); 115 | void(lua_insert)(struct lua_State*,int); 116 | void(lua_call)(struct lua_State*,int,int); 117 | int(lua_iscfunction)(struct lua_State*,int); 118 | void(luaL_openlib)(struct lua_State*,const char*,const struct luaL_Reg*,int); 119 | int(luaopen_ffi)(struct lua_State*); 120 | const char*(luaL_checklstring)(struct lua_State*,int,unsigned long*); 121 | int(luaopen_bit)(struct lua_State*); 122 | int(lua_isnumber)(struct lua_State*,int); 123 | void(lua_upvaluejoin)(struct lua_State*,int,int,int,int); 124 | void(lua_pushinteger)(struct lua_State*,long); 125 | void(lua_pushlightuserdata)(struct lua_State*,void*); 126 | int(lua_gethookcount)(struct lua_State*); 127 | void(lua_getfield)(struct lua_State*,int,const char*); 128 | void*(*lua_getallocf(struct lua_State*,void**))(void*,void*,unsigned long,unsigned long); 129 | int(lua_next)(struct lua_State*,int); 130 | const char*(lua_setupvalue)(struct lua_State*,int,int); 131 | int(luaL_newmetatable)(struct lua_State*,const char*); 132 | int(luaL_fileresult)(struct lua_State*,int,const char*); 133 | void(lua_copy)(struct lua_State*,int,int); 134 | int(lua_load)(struct lua_State*,const char*(*reader)(struct lua_State*,void*,unsigned long*),void*,const char*); 135 | int(lua_isuserdata)(struct lua_State*,int); 136 | int(*lua_tocfunction(struct lua_State*,int))(struct lua_State*); 137 | int(luaL_checkoption)(struct lua_State*,int,const char*,const char*const lst); 138 | int(luaopen_math)(struct lua_State*); 139 | int(luaopen_base)(struct lua_State*); 140 | int(luaopen_string)(struct lua_State*); 141 | int(luaopen_os)(struct lua_State*); 142 | void(lua_settable)(struct lua_State*,int); 143 | int(lua_setfenv)(struct lua_State*,int); 144 | int(lua_getstack)(struct lua_State*,int,struct lua_Debug*); 145 | void(lua_gettable)(struct lua_State*,int); 146 | int(lua_getinfo)(struct lua_State*,const char*,struct lua_Debug*); 147 | double(lua_tonumber)(struct lua_State*,int); 148 | int(lua_equal)(struct lua_State*,int,int); 149 | ]]) 150 | local CLIB = ffi.C 151 | local library = {} 152 | library = { 153 | setfield = CLIB.lua_setfield, 154 | xmove = CLIB.lua_xmove, 155 | newstate = CLIB.lua_newstate, 156 | cpcall = CLIB.lua_cpcall, 157 | status = CLIB.lua_status, 158 | pushboolean = CLIB.lua_pushboolean, 159 | replace = CLIB.lua_replace, 160 | pushfstring = CLIB.lua_pushfstring, 161 | getlocal = CLIB.lua_getlocal, 162 | gettop = CLIB.lua_gettop, 163 | remove = CLIB.lua_remove, 164 | sethook = CLIB.lua_sethook, 165 | tothread = CLIB.lua_tothread, 166 | setallocf = CLIB.lua_setallocf, 167 | gethookmask = CLIB.lua_gethookmask, 168 | pushnumber = CLIB.lua_pushnumber, 169 | pushvalue = CLIB.lua_pushvalue, 170 | resume = CLIB.lua_resume, 171 | pushlstring = CLIB.lua_pushlstring, 172 | close = CLIB.lua_close, 173 | checkstack = CLIB.lua_checkstack, 174 | dump = CLIB.lua_dump, 175 | gethook = CLIB.lua_gethook, 176 | tointegerx = CLIB.lua_tointegerx, 177 | type = CLIB.lua_type, 178 | setmetatable = CLIB.lua_setmetatable, 179 | rawseti = CLIB.lua_rawseti, 180 | setlocal = CLIB.lua_setlocal, 181 | isstring = CLIB.lua_isstring, 182 | tonumberx = CLIB.lua_tonumberx, 183 | --setlevel = CLIB.lua_setlevel, 184 | pushstring = CLIB.lua_pushstring, 185 | rawset = CLIB.lua_rawset, 186 | pushcclosure = CLIB.lua_pushcclosure, 187 | loadx = CLIB.lua_loadx, 188 | objlen = CLIB.lua_objlen, 189 | gc = CLIB.lua_gc, 190 | atpanic = CLIB.lua_atpanic, 191 | typename = CLIB.lua_typename, 192 | createtable = CLIB.lua_createtable, 193 | newuserdata = CLIB.lua_newuserdata, 194 | pcall = CLIB.lua_pcall, 195 | lessthan = CLIB.lua_lessthan, 196 | pushthread = CLIB.lua_pushthread, 197 | topointer = CLIB.lua_topointer, 198 | error = CLIB.lua_error, 199 | isyieldable = CLIB.lua_isyieldable, 200 | rawequal = CLIB.lua_rawequal, 201 | version = CLIB.lua_version, 202 | getupvalue = CLIB.lua_getupvalue, 203 | rawget = CLIB.lua_rawget, 204 | pushnil = CLIB.lua_pushnil, 205 | pushvfstring = CLIB.lua_pushvfstring, 206 | rawgeti = CLIB.lua_rawgeti, 207 | toboolean = CLIB.lua_toboolean, 208 | concat = CLIB.lua_concat, 209 | getmetatable = CLIB.lua_getmetatable, 210 | newthread = CLIB.lua_newthread, 211 | yield = CLIB.lua_yield, 212 | upvalueid = CLIB.lua_upvalueid, 213 | touserdata = CLIB.lua_touserdata, 214 | settop = CLIB.lua_settop, 215 | getfenv = CLIB.lua_getfenv, 216 | tointeger = CLIB.lua_tointeger, 217 | tolstring = CLIB.lua_tolstring, 218 | insert = CLIB.lua_insert, 219 | call = CLIB.lua_call, 220 | iscfunction = CLIB.lua_iscfunction, 221 | isnumber = CLIB.lua_isnumber, 222 | upvaluejoin = CLIB.lua_upvaluejoin, 223 | pushinteger = CLIB.lua_pushinteger, 224 | pushlightuserdata = CLIB.lua_pushlightuserdata, 225 | gethookcount = CLIB.lua_gethookcount, 226 | getfield = CLIB.lua_getfield, 227 | getallocf = CLIB.lua_getallocf, 228 | next = CLIB.lua_next, 229 | setupvalue = CLIB.lua_setupvalue, 230 | copy = CLIB.lua_copy, 231 | load = CLIB.lua_load, 232 | isuserdata = CLIB.lua_isuserdata, 233 | tocfunction = CLIB.lua_tocfunction, 234 | settable = CLIB.lua_settable, 235 | setfenv = CLIB.lua_setfenv, 236 | getstack = CLIB.lua_getstack, 237 | gettable = CLIB.lua_gettable, 238 | getinfo = CLIB.lua_getinfo, 239 | tonumber = CLIB.lua_tonumber, 240 | equal = CLIB.lua_equal, 241 | } 242 | library.L = { 243 | buffinit = CLIB.luaL_buffinit, 244 | optnumber = CLIB.luaL_optnumber, 245 | pushresult = CLIB.luaL_pushresult, 246 | addstring = CLIB.luaL_addstring, 247 | loadbuffer = CLIB.luaL_loadbuffer, 248 | prepbuffer = CLIB.luaL_prepbuffer, 249 | setmetatable = CLIB.luaL_setmetatable, 250 | checktype = CLIB.luaL_checktype, 251 | pushmodule = CLIB.luaL_pushmodule, 252 | unref = CLIB.luaL_unref, 253 | traceback = CLIB.luaL_traceback, 254 | loadfilex = CLIB.luaL_loadfilex, 255 | ref = CLIB.luaL_ref, 256 | callmeta = CLIB.luaL_callmeta, 257 | execresult = CLIB.luaL_execresult, 258 | loadstring = CLIB.luaL_loadstring, 259 | checknumber = CLIB.luaL_checknumber, 260 | gsub = CLIB.luaL_gsub, 261 | error = CLIB.luaL_error, 262 | where = CLIB.luaL_where, 263 | optinteger = CLIB.luaL_optinteger, 264 | checkany = CLIB.luaL_checkany, 265 | testudata = CLIB.luaL_testudata, 266 | checkstack = CLIB.luaL_checkstack, 267 | checkinteger = CLIB.luaL_checkinteger, 268 | optlstring = CLIB.luaL_optlstring, 269 | typerror = CLIB.luaL_typerror, 270 | findtable = CLIB.luaL_findtable, 271 | getmetafield = CLIB.luaL_getmetafield, 272 | register = CLIB.luaL_register, 273 | newstate = CLIB.luaL_newstate, 274 | addlstring = CLIB.luaL_addlstring, 275 | loadbufferx = CLIB.luaL_loadbufferx, 276 | argerror = CLIB.luaL_argerror, 277 | loadfile = CLIB.luaL_loadfile, 278 | checkudata = CLIB.luaL_checkudata, 279 | openlibs = CLIB.luaL_openlibs, 280 | setfuncs = CLIB.luaL_setfuncs, 281 | addvalue = CLIB.luaL_addvalue, 282 | openlib = CLIB.luaL_openlib, 283 | checklstring = CLIB.luaL_checklstring, 284 | newmetatable = CLIB.luaL_newmetatable, 285 | fileresult = CLIB.luaL_fileresult, 286 | checkoption = CLIB.luaL_checkoption, 287 | } 288 | library.e = { 289 | } 290 | library.clib = CLIB 291 | return library 292 | -------------------------------------------------------------------------------- /luajit_forks/.gitignore: -------------------------------------------------------------------------------- 1 | luajit_* 2 | lj.supp 3 | -------------------------------------------------------------------------------- /luajit_forks/build.lua: -------------------------------------------------------------------------------- 1 | local args = ... 2 | 3 | package.path = package.path .. ";../?.lua" 4 | local ffibuild = require("ffibuild") 5 | 6 | local repos = { 7 | --[[{ 8 | author = "mike", 9 | url = "https://github.com/LuaJIT/LuaJIT", 10 | branch = "v2.1", 11 | flags = {"LUAJIT_ENABLE_GC64", "LUAJIT_ENABLE_LUA52COMPAT"}, 12 | },]] 13 | { 14 | author = "lukego", 15 | url = "https://github.com/raptorjit/raptorjit", 16 | branch = "master", 17 | flags = {"LUAJIT_ENABLE_GC64", "LUAJIT_ENABLE_LUA52COMPAT"}, 18 | bin = "raptorjit", 19 | pre_make = "reusevm" 20 | }, 21 | } 22 | 23 | local parallel = "" 24 | 25 | local function build_flags(tbl) 26 | local flags = "" 27 | for _, flag in ipairs(tbl) do 28 | if flag:find("^LUA") then 29 | flag = "XCFLAGS+=-D" .. flag 30 | end 31 | 32 | flags = flags .. flag .. " " 33 | end 34 | return flags 35 | end 36 | 37 | local function build(info, extra_flags, extra_id) 38 | local id = info.id or (info.author or info.url:match(".+/(.+)/")) .. "-" .. info.branch 39 | 40 | if extra_id then 41 | id = id .. "_" .. extra_id 42 | end 43 | 44 | if info.flags then 45 | for _, flag in ipairs(info.flags) do 46 | id = id .. "_" .. flag:gsub("LUAJIT_", ""):gsub("LUA", ""):gsub("ENABLE_", "") 47 | end 48 | end 49 | 50 | id = id:lower() 51 | 52 | local dir = "repo/" .. id 53 | 54 | local flags = "" 55 | 56 | if info.flags then 57 | flags = build_flags(info.flags) 58 | end 59 | 60 | if extra_flags then 61 | flags = flags .. build_flags(extra_flags) 62 | end 63 | 64 | local patch_cmd = "" 65 | 66 | if info.patches then 67 | for i, patch in ipairs(info.patches) do 68 | os.execute("mkdir -p " .. dir) 69 | local f = assert(io.open(dir .. "/" .. i .. ".patch", "wb")) 70 | f:write(patch) 71 | f:close() 72 | patch_cmd = patch_cmd .. "git -C ./".. dir .. " apply " .. i .. ".patch;\n" 73 | end 74 | end 75 | 76 | local name = info.bin or "luajit" 77 | local commit = info.commit or "HEAD" 78 | 79 | local pre_make = "" 80 | if info.pre_make then 81 | pre_make = "make -C " .. dir .. " " .. info.pre_make .. ";\n" 82 | end 83 | 84 | 85 | local fetch = "if [ -d ./" .. dir .. " ]; then git -C ./" .. dir .. " pull; git -C ./" .. dir .. " checkout " .. commit .. "; else git clone -b " .. info.branch .. " " .. info.url .. " " .. dir .. " --depth 1; fi" .. "; " 86 | local build = patch_cmd .. pre_make .. "make -C " .. dir .. " " .. flags .. ";\n" 87 | 88 | if os.isfile("luajit_" .. id) then 89 | build = "" 90 | fetch = "" 91 | end 92 | 93 | parallel = parallel .. 94 | "(\n" .. 95 | fetch .. 96 | build .. 97 | "cp " .. dir .. "/src/"..name.." luajit_" .. id .. ";\n" .. 98 | "cp " .. dir .. "/src/lj.supp lj.supp;\n" .. 99 | "\n) &\n" 100 | end 101 | 102 | local url_filter = args 103 | 104 | for _, info in pairs(repos) do 105 | if not url_filter or info.url:lower():find(url_filter) then 106 | build(info) 107 | build(info, { 108 | "LUA_USE_APICHECK", 109 | "LUAJIT_USE_GDBJIT", 110 | "CCDEBUG=-g", 111 | }, "debug") 112 | 113 | build(info, { 114 | "LUA_USE_APICHECK", 115 | "LUAJIT_USE_GDBJIT", 116 | "LUAJIT_USE_SYSMALLOC", 117 | "LUAJIT_USE_VALGRIND", 118 | "CCDEBUG=-g", 119 | }, "debug-memory") 120 | 121 | build(info, { 122 | "LUA_USE_APICHECK", 123 | "LUAJIT_USE_GDBJIT", 124 | "LUAJIT_USE_SYSMALLOC", 125 | "LUAJIT_USE_VALGRIND", 126 | "LUA_USE_ASSERT", 127 | "CCDEBUG=-g", 128 | }, "debug-memory-assert") 129 | end 130 | end 131 | 132 | print(parallel) 133 | os.execute(parallel .. " wait") 134 | -------------------------------------------------------------------------------- /luajit_forks/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /luaossl/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.checkcmds("cmake", "git", "make") 5 | 6 | local target = jit.os == "OSX" and "macosx" or "linux" 7 | local ext = jit.os == "OSX" and ".dylib" or ".so" 8 | local luajit_src = io.popen("echo $(realpath ../luajit/repo/src)", "r"):read("*all"):sub(0,-2) 9 | local luajit_lib = "libluajit.a" 10 | local inc = "-I" .. luajit_src 11 | local lib = "-l:" .. luajit_lib .. " " .. "-L" .. luajit_src 12 | 13 | ffibuild.ManualBuild( 14 | "luaossl", 15 | "https://github.com/wahern/luaossl.git", 16 | "make CPPFLAGS=\""..inc.."\" LDFLAGS=\""..lib.."\"", 17 | "cp repo/src/5.1/openssl.so _openssl.so && mkdir -p openssl && cp -r repo/src/*.lua openssl/ && cd openssl && for f in *.lua; do mv \"$f\" \"${f#openssl.}\"; done" 18 | ) 19 | 20 | if os.isfile("_openssl.so") then 21 | os.execute("../luajit/repo/src/luajit -e \"for k,v in pairs(require('openssl.hmac')) do print(k,v) end\"") 22 | end 23 | -------------------------------------------------------------------------------- /luaossl/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /luasec/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.checkcmds("cmake", "git", "make") 5 | 6 | local target = jit.os == "OSX" and "macosx" or "linux" 7 | local ext = jit.os == "OSX" and ".dylib" or ".so" 8 | local luajit_src = io.popen("echo $(realpath ../luajit/repo/src)", "r"):read("*all"):sub(0,-2) 9 | local luajit_lib = "libluajit.a" 10 | local inc = "-I" .. luajit_src 11 | local lib = "-l:" .. luajit_lib .. " " .. "-L" .. luajit_src 12 | 13 | ffibuild.ManualBuild( 14 | "luasec", 15 | "https://github.com/brunoos/luasec.git", 16 | "make " .. (jit.os == "Linux" and "linux" or jit.os == "OSX" and "macosx") .. " INC_PATH=\""..inc.."\" LIB_PATH=\""..lib.."\"", 17 | "cp repo/src/ssl.so . && mkdir -p ssl && cp -r repo/src/*.lua ssl/" 18 | ) 19 | 20 | if os.isfile("ssl.so") then 21 | os.execute("../luajit/repo/src/luajit -e \"for k,v in pairs(require('ssl.ssl')) do print(k,v) end\"") 22 | end 23 | -------------------------------------------------------------------------------- /luasec/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /luasec_nix/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | ffibuild.NixBuild({ 5 | package_name = "pkgs.luajitPackages.luasec.overrideAttrs (oldAttrs: {src = fetchFromGitHub {owner = \"brunoos\"; repo = \"luasec\";}; buildInputs = [ luajit openssl_1_1_0 ];})", 6 | custom = [[ 7 | 8 | ]], 9 | library_name = "lua/5.1/ssl" 10 | }) 11 | -------------------------------------------------------------------------------- /luasec_nix/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /luasocket/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | ffibuild.NixBuild({ 5 | package_name = "luajitPackages.luasocket", 6 | library_name = "lua/5.1/*" 7 | }) -------------------------------------------------------------------------------- /luasocket/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /mpg123/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | os.setenv("NIXPKGS_ALLOW_BROKEN", "1") 5 | 6 | local header = ffibuild.NixBuild({ 7 | package_name = "mpg123", 8 | -- library_name = "libmp3lame", 9 | src = [[ 10 | #include "mpg123.h" 11 | ]] 12 | }) 13 | 14 | local meta_data = ffibuild.GetMetaData(header) 15 | 16 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^mpg123_") end, function(name) return name:find("^MPG123_") end, true, true) 17 | 18 | local lua = ffibuild.StartLibrary(header) 19 | 20 | lua = lua .. "library = " .. meta_data:BuildFunctions("^mpg123_(.+)", "foo_bar", "FooBar") 21 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^MPG123_(.+)") 22 | 23 | ffibuild.EndLibrary(lua, header) 24 | -------------------------------------------------------------------------------- /mpg123/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /ode/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | 5 | ffibuild.ManualBuild( 6 | "ode", 7 | "hg clone https://bitbucket.org/odedevs/ode repo", 8 | "./bootstrap && ./configure --enable-shared --enable-double-precision --with-libccd=system --with-gimpact --with-libccd && make" 9 | ) 10 | 11 | local header = ffibuild.ProcessSourceFileGCC([[ 12 | #include "ode/ode.h" 13 | 14 | ]], "-I./repo/include") 15 | local meta_data = ffibuild.GetMetaData(header) 16 | 17 | meta_data.functions.dThreadingImplementationGetFunctions = nil 18 | meta_data.functions.dWorldSetStepThreadingImplementation = nil 19 | meta_data.functions.dCreateGeomClass = nil 20 | meta_data.functions.dJointAddPUTorque = nil 21 | meta_data.functions.dGeomTriMeshDataGet = nil 22 | 23 | --for k,v in pairs(meta_data.structs["struct dJointFeedback"].data) do print(v, meta_data.typedefs.dVector3:GetDeclaration(meta_data), v:GetDeclaration(meta_data), v.array_size, "!!") end 24 | --print(meta_data.typedefs.dVector3.array_size) 25 | --do return end 26 | 27 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^d%u") end, function(name) return name:find("^d%u") end, true, true) 28 | 29 | local lua = ffibuild.StartLibrary(header) 30 | 31 | lua = lua .. "library = " .. meta_data:BuildFunctions("^d(%u.+)") 32 | lua = lua .. "library.e = " .. meta_data:BuildEnums("^d(%u.+)") 33 | 34 | ffibuild.EndLibrary(lua, header) 35 | -------------------------------------------------------------------------------- /ode/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /openal/alc.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | ffi.cdef([[struct ALCdevice_struct {}; 3 | struct ALCcontext_struct {}; 4 | void(alcDestroyContext)(struct ALCcontext_struct*); 5 | void(alcCaptureStop)(struct ALCdevice_struct*); 6 | void(alcGetIntegerv)(struct ALCdevice_struct*,int,int,int*); 7 | void(alcCaptureSamples)(struct ALCdevice_struct*,void*,int); 8 | const char*(alcGetString)(struct ALCdevice_struct*,int); 9 | struct ALCcontext_struct*(alcGetCurrentContext)(); 10 | struct ALCcontext_struct*(alcGetThreadContext)(); 11 | int(alcGetError)(struct ALCdevice_struct*); 12 | char(alcResetDeviceSOFT)(struct ALCdevice_struct*,const int*); 13 | void(alcRenderSamplesSOFT)(struct ALCdevice_struct*,void*,int); 14 | void(alcDeviceResumeSOFT)(struct ALCdevice_struct*); 15 | void*(alcGetProcAddress)(struct ALCdevice_struct*,const char*); 16 | struct ALCcontext_struct*(alcCreateContext)(struct ALCdevice_struct*,const int*); 17 | const char*(alcGetStringiSOFT)(struct ALCdevice_struct*,int,int); 18 | void(alcDevicePauseSOFT)(struct ALCdevice_struct*); 19 | void(alcSuspendContext)(struct ALCcontext_struct*); 20 | struct ALCdevice_struct*(alcOpenDevice)(const char*); 21 | char(alcMakeContextCurrent)(struct ALCcontext_struct*); 22 | struct ALCdevice_struct*(alcGetContextsDevice)(struct ALCcontext_struct*); 23 | int(alcGetEnumValue)(struct ALCdevice_struct*,const char*); 24 | char(alcIsRenderFormatSupportedSOFT)(struct ALCdevice_struct*,int,int,int); 25 | char(alcSetThreadContext)(struct ALCcontext_struct*); 26 | char(alcCaptureCloseDevice)(struct ALCdevice_struct*); 27 | struct ALCdevice_struct*(alcCaptureOpenDevice)(const char*,unsigned int,int,int); 28 | char(alcIsExtensionPresent)(struct ALCdevice_struct*,const char*); 29 | void(alcCaptureStart)(struct ALCdevice_struct*); 30 | void(alcProcessContext)(struct ALCcontext_struct*); 31 | char(alcCloseDevice)(struct ALCdevice_struct*); 32 | struct ALCdevice_struct*(alcLoopbackOpenDeviceSOFT)(const char*); 33 | ]]) 34 | local CLIB = ffi.load(_G.FFI_LIB or "openal") 35 | local library = {} 36 | library = { 37 | DestroyContext = CLIB.alcDestroyContext, 38 | CaptureStop = CLIB.alcCaptureStop, 39 | GetIntegerv = CLIB.alcGetIntegerv, 40 | CaptureSamples = CLIB.alcCaptureSamples, 41 | GetString = CLIB.alcGetString, 42 | GetCurrentContext = CLIB.alcGetCurrentContext, 43 | GetThreadContext = CLIB.alcGetThreadContext, 44 | GetError = CLIB.alcGetError, 45 | ResetDeviceSOFT = CLIB.alcResetDeviceSOFT, 46 | RenderSamplesSOFT = CLIB.alcRenderSamplesSOFT, 47 | DeviceResumeSOFT = CLIB.alcDeviceResumeSOFT, 48 | GetProcAddress = CLIB.alcGetProcAddress, 49 | CreateContext = CLIB.alcCreateContext, 50 | GetStringiSOFT = CLIB.alcGetStringiSOFT, 51 | DevicePauseSOFT = CLIB.alcDevicePauseSOFT, 52 | SuspendContext = CLIB.alcSuspendContext, 53 | OpenDevice = CLIB.alcOpenDevice, 54 | MakeContextCurrent = CLIB.alcMakeContextCurrent, 55 | GetContextsDevice = CLIB.alcGetContextsDevice, 56 | GetEnumValue = CLIB.alcGetEnumValue, 57 | IsRenderFormatSupportedSOFT = CLIB.alcIsRenderFormatSupportedSOFT, 58 | SetThreadContext = CLIB.alcSetThreadContext, 59 | CaptureCloseDevice = CLIB.alcCaptureCloseDevice, 60 | CaptureOpenDevice = CLIB.alcCaptureOpenDevice, 61 | IsExtensionPresent = CLIB.alcIsExtensionPresent, 62 | CaptureStart = CLIB.alcCaptureStart, 63 | ProcessContext = CLIB.alcProcessContext, 64 | CloseDevice = CLIB.alcCloseDevice, 65 | LoopbackOpenDeviceSOFT = CLIB.alcLoopbackOpenDeviceSOFT, 66 | } 67 | local AL_TRUE = 1 68 | local AL_FALSE = 0 69 | local AL_INVALID_ENUM = 40962 70 | library.e = { 71 | API = 1, 72 | API = extern, 73 | APIENTRY = __cdecl, 74 | APIENTRY = 1, 75 | INVALID = 0, 76 | VERSION_0_1 = 1, 77 | FALSE = 0, 78 | TRUE = 1, 79 | FREQUENCY = 4103, 80 | REFRESH = 4104, 81 | SYNC = 4105, 82 | MONO_SOURCES = 4112, 83 | STEREO_SOURCES = 4113, 84 | NO_ERROR = 0, 85 | INVALID_DEVICE = 40961, 86 | INVALID_CONTEXT = 40962, 87 | INVALID_ENUM = 40963, 88 | INVALID_VALUE = 40964, 89 | OUT_OF_MEMORY = 40965, 90 | MAJOR_VERSION = 4096, 91 | MINOR_VERSION = 4097, 92 | ATTRIBUTES_SIZE = 4098, 93 | ALL_ATTRIBUTES = 4099, 94 | DEFAULT_DEVICE_SPECIFIER = 4100, 95 | DEVICE_SPECIFIER = 4101, 96 | EXTENSIONS = 4102, 97 | EXT_CAPTURE = 1, 98 | CAPTURE_DEVICE_SPECIFIER = 784, 99 | CAPTURE_DEFAULT_DEVICE_SPECIFIER = 785, 100 | CAPTURE_SAMPLES = 786, 101 | ENUMERATE_ALL_EXT = 1, 102 | DEFAULT_ALL_DEVICES_SPECIFIER = 4114, 103 | ALL_DEVICES_SPECIFIER = 4115, 104 | LOKI_audio_channel = 1, 105 | CHAN_MAIN_LOKI = 5242881, 106 | CHAN_PCM_LOKI = 5242882, 107 | CHAN_CD_LOKI = 5242883, 108 | EXT_EFX = 1, 109 | EXT_disconnect = 1, 110 | CONNECTED = 787, 111 | EXT_thread_local_context = 1, 112 | EXT_DEDICATED = 1, 113 | SOFT_loopback = 1, 114 | FORMAT_CHANNELS_SOFT = 6544, 115 | FORMAT_TYPE_SOFT = 6545, 116 | BYTE_SOFT = 5120, 117 | UNSIGNED_BYTE_SOFT = 5121, 118 | SHORT_SOFT = 5122, 119 | UNSIGNED_SHORT_SOFT = 5123, 120 | INT_SOFT = 5124, 121 | UNSIGNED_INT_SOFT = 5125, 122 | FLOAT_SOFT = 5126, 123 | MONO_SOFT = 5376, 124 | STEREO_SOFT = 5377, 125 | QUAD_SOFT = 5379, 126 | _5POINT1_SOFT = 5380, 127 | _6POINT1_SOFT = 5381, 128 | _7POINT1_SOFT = 5382, 129 | EXT_DEFAULT_FILTER_ORDER = 1, 130 | DEFAULT_FILTER_ORDER = 4352, 131 | SOFT_pause_device = 1, 132 | SOFT_HRTF = 1, 133 | HRTF_SOFT = 6546, 134 | DONT_CARE_SOFT = 2, 135 | HRTF_STATUS_SOFT = 6547, 136 | HRTF_DISABLED_SOFT = 0, 137 | HRTF_ENABLED_SOFT = 1, 138 | HRTF_DENIED_SOFT = 2, 139 | HRTF_REQUIRED_SOFT = 3, 140 | HRTF_HEADPHONES_DETECTED_SOFT = 4, 141 | HRTF_UNSUPPORTED_FORMAT_SOFT = 5, 142 | NUM_HRTF_SPECIFIERS_SOFT = 6548, 143 | HRTF_SPECIFIER_SOFT = 6549, 144 | HRTF_ID_SOFT = 6550, 145 | SOFT_output_limiter = 1, 146 | OUTPUT_LIMITER_SOFT = 6554, 147 | EXT_EFX_NAME = "ALC_EXT_EFX", 148 | EFX_MAJOR_VERSION = 131073, 149 | EFX_MINOR_VERSION = 131074, 150 | MAX_AUXILIARY_SENDS = 131075, 151 | } 152 | function library.GetErrorString(device) 153 | local num = library.GetError(device) 154 | 155 | if num == library.e.NO_ERROR then 156 | return "no error" 157 | elseif num == library.e.INVALID_DEVICE then 158 | return "invalid device" 159 | elseif num == library.e.INVALID_CONTEXT then 160 | return "invalid context" 161 | elseif num == library.e.INVALID_ENUM then 162 | return "invalid enum" 163 | elseif num == library.e.INVALID_VALUE then 164 | return "invalid value" 165 | elseif num == library.e.OUT_OF_MEMORY then 166 | return "out of memory" 167 | end 168 | end 169 | library.clib = CLIB 170 | return library 171 | -------------------------------------------------------------------------------- /openal/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | for lib_name, enum_name in pairs({al = "AL_", alc = "ALC_"}) do 5 | ffibuild.SetBuildName(lib_name) 6 | 7 | local headers = { 8 | "alc", 9 | "alext", 10 | "al", 11 | "efx", 12 | } 13 | 14 | local c_source = [[ 15 | #define AL_ALEXT_PROTOTYPES 16 | ]] 17 | 18 | for _, name in ipairs(headers) do 19 | c_source = c_source .. "#include \"AL/" .. name .. ".h\"\n" 20 | end 21 | 22 | local header = ffibuild.NixBuild({ 23 | package_name = "openal", 24 | src = c_source 25 | }) 26 | 27 | do 28 | local args = {} 29 | 30 | for _, name in ipairs(headers) do 31 | table.insert(args, {"./include/AL/" .. name .. ".h", enum_name}) 32 | end 33 | end 34 | 35 | local meta_data = ffibuild.GetMetaData(header) 36 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^"..lib_name.."%u") end, function(name) return name:find("^" .. enum_name) end, true, true) 37 | 38 | ffibuild.lib_name = "openal" 39 | local lua = ffibuild.StartLibrary(header) 40 | 41 | ffibuild.lib_name = lib_name 42 | 43 | if lib_name == "al" then 44 | lua = lua .. [[ 45 | local function get_proc_address(func, cast) 46 | local ptr = CLIB.alGetProcAddress(func) 47 | if ptr ~= nil then 48 | return ffi.cast(cast, ptr) 49 | end 50 | end 51 | ]] 52 | 53 | lua = lua .. "library = {\n" 54 | for func_name, type in pairs(meta_data.functions) do 55 | local friendly = func_name:match("^"..lib_name.."(%u.+)") 56 | if friendly then 57 | lua = lua .. "\t" .. friendly .. " = get_proc_address(\""..func_name.."\", \""..type:GetDeclaration(meta_data, "*", "").."\"),\n" 58 | end 59 | end 60 | lua = lua .. "}\n" 61 | else 62 | lua = lua .. "library = " .. meta_data:BuildFunctions("^"..lib_name.."(%u.+)") 63 | end 64 | 65 | local args = {} 66 | 67 | for _, name in ipairs(headers) do 68 | table.insert(args, {"./include/AL/" .. name .. ".h", enum_name}) 69 | end 70 | 71 | lua = lua .. "local AL_TRUE = 1\n" 72 | lua = lua .. "local AL_FALSE = 0\n" 73 | lua = lua .. "local AL_INVALID_ENUM = 40962\n" 74 | 75 | local enums = meta_data:BuildEnums("^"..enum_name.."(.+)", args) 76 | 77 | lua = lua .. "library.e = " .. enums 78 | 79 | if lib_name == "al" then 80 | 81 | local function gen_available_params(type, user_unavailable) -- effect params 82 | local available = {} 83 | 84 | local unavailable = { 85 | last_parameter = true, 86 | first_parameter = true, 87 | type = true, 88 | null = true, 89 | } 90 | 91 | local enums = loadstring("return " .. enums)() 92 | 93 | for k,v in pairs(user_unavailable) do 94 | unavailable[v] = true 95 | end 96 | 97 | local type_pattern = type:upper().."_(.+)" 98 | 99 | for key, val in pairs(enums) do 100 | local type = key:match(type_pattern) 101 | 102 | if type then 103 | type = type:lower() 104 | if not unavailable[type] then 105 | available[type] = {enum = val, params = {}} 106 | end 107 | end 108 | end 109 | 110 | for name, data in pairs(available) do 111 | for key, val in pairs(enums) do 112 | local param = key:match(name:upper() .. "_(.+)") 113 | 114 | if param then 115 | local name = param:lower() 116 | 117 | if param:find("DEFAULT_") then 118 | name = param:match("DEFAULT_(.+)") 119 | key = "default" 120 | elseif param:find("MIN_") then 121 | name = param:match("MIN_(.+)") 122 | key = "min" 123 | elseif param:find("MAX_") then 124 | name = param:match("MAX_(.+)") 125 | key = "max" 126 | else 127 | key = "enum" 128 | end 129 | 130 | name = name:lower() 131 | 132 | data.params[name] = data.params[name] or {} 133 | data.params[name][key] = val 134 | end 135 | end 136 | end 137 | 138 | lua = lua .. "library." .. type .. "Params = {\n" 139 | for type, info in pairs(available) do 140 | lua = lua .. "\t" .. type .. " = {\n" 141 | lua = lua .. "\t\t" .. "enum = " .. tostring(info.enum) .. ",\n" 142 | lua = lua .. "\t\t" .. "params = {\n" 143 | for key, tbl in pairs(info.params) do 144 | lua = lua .. "\t\t\t" .. key .. " = {\n" 145 | for key, val in pairs(tbl) do 146 | lua = lua .. "\t\t\t\t" .. key .. " = " .. tostring(val) .. ",\n" 147 | end 148 | lua = lua .. "\t\t\t" .. "},\n" 149 | end 150 | lua = lua .. "\t\t" .. "},\n" 151 | lua = lua .. "\t" .. "},\n" 152 | end 153 | lua = lua .. "}\n" 154 | 155 | lua = lua .. "function library.GetAvailable" .. type .. "s()\n\treturn library." .. type .. "Params\nend\n" 156 | end 157 | 158 | gen_available_params("Effect", {"pitch_shifter", "vocal_morpher", "frequency_shifter"}) 159 | gen_available_params("Filter", {"highpass", "bandpass"}) 160 | end 161 | 162 | for func_name in pairs(meta_data.functions) do 163 | local friendly = func_name:match("^"..lib_name.."(%u.+)") 164 | if friendly and friendly:find("^Gen%u%l") then 165 | local new_name = friendly:sub(0,-2) -- remove the last "s" 166 | lua = lua .. 167 | [[function library.]]..new_name..[[() 168 | local id = ffi.new("unsigned int[1]") 169 | library.]]..friendly..[[(1, id) 170 | return id[0] 171 | end 172 | ]] 173 | end 174 | end 175 | 176 | 177 | if lib_name == "alc" then 178 | lua = lua .. [[ 179 | function library.GetErrorString(device) 180 | local num = library.GetError(device) 181 | 182 | if num == library.e.NO_ERROR then 183 | return "no error" 184 | elseif num == library.e.INVALID_DEVICE then 185 | return "invalid device" 186 | elseif num == library.e.INVALID_CONTEXT then 187 | return "invalid context" 188 | elseif num == library.e.INVALID_ENUM then 189 | return "invalid enum" 190 | elseif num == library.e.INVALID_VALUE then 191 | return "invalid value" 192 | elseif num == library.e.OUT_OF_MEMORY then 193 | return "out of memory" 194 | end 195 | end 196 | ]] 197 | elseif lib_name == "al" then 198 | lua = lua .. [[ 199 | function library.GetErrorString() 200 | local num = library.GetError() 201 | 202 | if num == library.e.NO_ERROR then 203 | return "no error" 204 | elseif num == library.e.INVALID_NAME then 205 | return "invalid name" 206 | elseif num == library.e.INVALID_ENUM then 207 | return "invalid enum" 208 | elseif num == library.e.INVALID_VALUE then 209 | return "invalid value" 210 | elseif num == library.e.INVALID_OPERATION then 211 | return "invalid operation" 212 | elseif num == library.e.OUT_OF_MEMORY then 213 | return "out of memory" 214 | end 215 | end 216 | ]] 217 | end 218 | 219 | 220 | ffibuild.EndLibrary(lua, header) 221 | end -------------------------------------------------------------------------------- /openal/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /opengl/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") -------------------------------------------------------------------------------- /opengl/build_from_xml.lua: -------------------------------------------------------------------------------- 1 | local xml = vfs.Read("gl.xml") 2 | 3 | local manual_enum_group_fixup = { 4 | texture = { 5 | target = "TextureTarget", 6 | pname = "GetTextureParameter", 7 | } 8 | } 9 | 10 | local enum_group_name_strip = { 11 | texture = "texture", 12 | } 13 | 14 | local pseduo_objects = { 15 | NamedFramebuffer = { 16 | name = "Framebuffer", 17 | }, 18 | Texture = { 19 | name = "Tex", 20 | functions = { 21 | GetTexImage = { 22 | arg_line1 = "level, format, type, bufSize, pixels", 23 | arg_line2 = "self.target, level, format, type, pixels", 24 | }, 25 | 26 | -- first argument must be GL_TEXTURE_BUFFER 27 | TexBufferRange = { 28 | static_arguments = {"GL_TEXTURE_BUFFER"} 29 | }, 30 | TexBufferRangeEXT = { 31 | static_arguments = {"GL_TEXTURE_BUFFER"} 32 | }, 33 | TexBuffer = { 34 | static_arguments = {"GL_TEXTURE_BUFFER"} 35 | } 36 | }, 37 | } 38 | } 39 | 40 | local enums = {} 41 | 42 | for value, enum in xml:gmatch("") do 51 | enum_groups[group] = {} 52 | for enum in enums_:gmatch("name=\"(.-)\"/>") do 53 | local friendly = enum:lower():sub(4) 54 | 55 | for k,v in pairs(enum_group_name_strip) do 56 | if group:lower():find(k, nil, true) then 57 | friendly = friendly:gsub(v, ""):trim("_") 58 | break 59 | end 60 | end 61 | 62 | enum_groups[group][friendly] = enums[enum] 63 | end 64 | end 65 | 66 | local friendly_enums = {} 67 | for k,v in pairs(enums) do 68 | friendly_enums[k:lower():sub(4)] = v 69 | end 70 | 71 | enum_groups.not_found = friendly_enums 72 | 73 | local functions = {} 74 | 75 | for str in xml:gmatch("(.-)") do 76 | local func_str = str:match("") 77 | local name = func_str:match("(.-)") 78 | local type = func_str:match("(.-)") 79 | local group = func_str:match("group=\"(.-)\"") 80 | 81 | local func_name = str:match("(.-)") 82 | local args = {} 83 | local i = 1 84 | 85 | local cast_str = (str:match("(.-)") or str:match("(.-)")) .. "(*)(" 86 | 87 | if cast_str:find("ptype", nil, true) then 88 | cast_str = cast_str:gsub("", "") 89 | cast_str = cast_str:gsub("", "") 90 | end 91 | 92 | for param in str:gmatch("") do 93 | local name = param:match("(.-)") 94 | local type = param:match("(.-)") 95 | type = type:gsub("", "") 96 | type = type:gsub("", "") 97 | type = type:trim() 98 | local group = param:match("group=\"(.-)\"") 99 | 100 | if not group then 101 | for k,v in pairs(manual_enum_group_fixup) do 102 | if func_name:lower():find(k, nil, true) then 103 | group = v[name] 104 | end 105 | end 106 | end 107 | 108 | if name == "end" then name = "_end" end 109 | if name == "in" then name = "_in" end 110 | 111 | local group_name = group 112 | group = enum_groups[group] 113 | 114 | if type == "GLenum" then 115 | type = "GL_LUA_ENUMS" 116 | end 117 | 118 | cast_str = cast_str .. type .. ", " 119 | 120 | args[i] = { 121 | type = type, 122 | group = group, 123 | group_name = group_name, 124 | name = name 125 | } 126 | 127 | i = i + 1 128 | end 129 | 130 | cast_str = cast_str:sub(0,-3) .. ")" 131 | 132 | if cast_str:endswith("(*)") then cast_str = cast_str .. "()" end 133 | 134 | local get_function 135 | 136 | if func_name:find("Get", nil, true) and args[1] and args[#args].type:endswith("*") and not args[#args].type:find("void") then 137 | get_function = true 138 | end 139 | 140 | functions[func_name] = { 141 | args = args, 142 | type = type, 143 | group = group, 144 | name = name, 145 | cast_str = cast_str, 146 | get_function = get_function, 147 | } 148 | end 149 | 150 | local objects = {} 151 | 152 | for name, str in xml:gmatch("(.-)") do 153 | if not name:find("\n") then 154 | name = name:gsub("%s+", "") 155 | 156 | objects[name] = {} 157 | 158 | local found = {} 159 | 160 | local name2 161 | if str:find("Named" .. name, nil, true) then 162 | name2 = "Named" .. name 163 | end 164 | 165 | for func_name in str:gmatch("") do 166 | local friendly = func_name:sub(3):gsub(name2 or name, "") 167 | if friendly ~= "Creates" then 168 | found[friendly] = functions[func_name] 169 | end 170 | end 171 | 172 | for func_name,v in pairs(functions) do 173 | if v.args[1] and v.args[1].group_name == name then 174 | local friendly = func_name:sub(3):gsub(name2 or name, ""):gsub(name, "") 175 | 176 | if not friendly:startswith("Create") then 177 | found[friendly] = v 178 | end 179 | end 180 | end 181 | 182 | for k,v in pairs(found) do 183 | if found["Get" .. k] or found["Get" .. k .. "v"] then 184 | k = "Set" .. k 185 | end 186 | 187 | if k:endswith("EXT") and not found[k:sub(0,-4)] then 188 | k = k:sub(0,-4) 189 | end 190 | 191 | objects[name][k] = v 192 | end 193 | end 194 | end 195 | 196 | local gl = require("graphics.ffi.opengl") 197 | 198 | local lua = {} 199 | local i = 1 200 | local insert = function(s) lua[i] = s i=i+1 end 201 | 202 | insert"local gl = {}" 203 | insert"" 204 | insert"ffi.cdef[[" 205 | 206 | local done = {} 207 | 208 | for line in xml:match(".-"):gmatch("") do 209 | local cdef = line:match("(typedef.+;)") 210 | if cdef and not cdef:find("\n") and not cdef:find("khronos_") then 211 | cdef = cdef:gsub("", "") 212 | cdef = cdef:gsub("", "") 213 | cdef = cdef:gsub("", "") 214 | 215 | if not done[cdef] then 216 | insert(cdef) 217 | done[cdef] = true 218 | end 219 | end 220 | end 221 | 222 | insert("typedef enum GL_LUA_ENUMS {") 223 | local max = table.count(enums) 224 | local i = 1 225 | for name, val in pairs(enums) do 226 | local line = "\t" .. name .. " = " .. val 227 | 228 | if i ~= max then 229 | line = line .. ", " 230 | end 231 | 232 | insert(line) 233 | 234 | i = i + 1 235 | end 236 | insert("} GL_LUA_ENUMS;") 237 | 238 | insert"]]" 239 | 240 | insert"function gl.Initialize(get_proc_address)" 241 | insert"\tif type(get_proc_address) == \"function\" then" 242 | insert"\t\tgl.GetProcAddress = get_proc_address" 243 | insert"\tend" 244 | 245 | for k, func_info in pairs(functions) do 246 | local nice = func_info.name:sub(3) 247 | 248 | local arg_line = "" 249 | 250 | --http://stackoverflow.com/questions/15442615/how-to-determine-the-size-of-opengl-output-buffers-compsize 251 | 252 | for i, arg in ipairs(func_info.args) do 253 | local name = arg.name 254 | 255 | arg_line = arg_line .. name 256 | if i ~= #func_info.args then 257 | arg_line = arg_line .. ", " 258 | end 259 | end 260 | 261 | insert"\tdo" 262 | insert("\t\tlocal func = gl.GetProcAddress(\""..func_info.name.."\")") 263 | insert"\t\tif func ~= nil then" 264 | insert("\t\t\tlocal ok, func = pcall(ffi.cast, '"..func_info.cast_str.."', func)") 265 | insert"\t\t\tif ok then" 266 | 267 | insert("\t\t\t\tgl." .. nice .. " = func") 268 | 269 | if func_info.name:find("Gen%a-s$") then 270 | insert("\t\t\tgl." .. nice:sub(0,-2) .. " = function() local id = ffi.new('GLint[1]') func(1, id) return id[0] end") 271 | end 272 | 273 | insert"\t\t\tend" 274 | insert"\t\tend" 275 | insert"\tend" 276 | 277 | func_info.arg_line = arg_line 278 | end 279 | 280 | for name, object_functions in pairs(objects) do 281 | local create = functions["glCreate" .. name .. "s"] 282 | local delete = functions["glDelete" .. name .. "s"] 283 | 284 | if create and delete then 285 | insert("\tdo -- " .. name) 286 | insert"\t\tlocal META = {}" 287 | insert"\t\tMETA.__index = META" 288 | 289 | insert("\t\tif gl.Create"..name.."s then") 290 | for friendly, info in pairs(object_functions) do 291 | local arg_line = info.arg_line:match(".-, (.+)") or "" 292 | insert("\t\t\tfunction META:" .. friendly .. "(" .. arg_line .. ")") 293 | if arg_line ~= "" then arg_line = ", " .. arg_line end 294 | insert("\t\t\t\treturn gl." .. info.name:sub(3) .. "(self.id" .. arg_line .. ")") 295 | insert"\t\t\tend" 296 | end 297 | 298 | 299 | insert("\t\t\tlocal ctype = ffi.typeof('struct { int id; }')") 300 | insert"\t\t\tffi.metatype(ctype, META)" 301 | 302 | insert("\t\t\tlocal temp = ffi.new('GLuint[1]')") 303 | 304 | insert"\t\t\tfunction META:Delete()" 305 | insert"\t\t\t\ttemp[0] = self.id" 306 | insert("\t\t\t\tgl." .. delete.name:sub(3) .. "(1, temp)") 307 | insert"\t\t\tend" 308 | 309 | local arg_line = create.arg_line:match("(.+),.-,+") or "" 310 | 311 | insert("\t\t\tfunction gl.Create" .. name .. "(" .. arg_line .. ")") 312 | if arg_line ~= "" then arg_line = arg_line .. ", " end 313 | insert("\t\t\t\tgl." .. create.name:sub(3) .. "(" .. arg_line .. "1, temp)") 314 | insert"\t\t\t\tlocal self = ffi.new(ctype)" 315 | insert"\t\t\t\tself.id = temp[0]" 316 | insert"\t\t\t\treturn self" 317 | insert"\t\t\tend" 318 | 319 | insert"\t\telse" 320 | 321 | local object_info = pseduo_objects[name] or {} 322 | 323 | insert"\t\t\tlocal bind" 324 | 325 | insert"\t\t\tdo" 326 | insert"\t\t\t\tlocal last" 327 | if name == "Framebuffer" then 328 | insert"\t\t\t\tfunction bind(self, target)" 329 | else 330 | insert"\t\t\t\tfunction bind(self)" 331 | end 332 | insert"\t\t\t\t\tif self ~= last then" 333 | if name == "Texture" then 334 | insert"\t\t\t\t\t\tgl.BindTexture(self.target, self.id)" 335 | elseif name == "Renderbuffer" then 336 | insert("\t\t\t\t\t\tgl.Bind"..name.."(\"GL_RENDERBUFFER\", self.id)") 337 | elseif name == "Framebuffer" then 338 | insert("\t\t\t\t\t\tgl.Bind"..name.."(target, self.id)") 339 | else 340 | insert("\t\t\t\t\t\tgl.Bind"..name.."(self.id)") 341 | end 342 | insert"\t\t\t\t\tend" 343 | insert"\t\t\t\t\tlast = self" 344 | insert"\t\t\t\tend" 345 | insert"\t\t\tend" 346 | 347 | for friendly, info in pairs(object_functions) do 348 | local func_name = info.name:sub(3) 349 | 350 | func_name = func_name:replace("Named", "") 351 | 352 | if object_info.name then 353 | local temp = func_name:replace(name, object_info.name) 354 | 355 | if not functions["gl"..temp] then 356 | temp = func_name:replace(name, "") 357 | if not functions["gl"..temp] then 358 | temp = func_name 359 | end 360 | end 361 | 362 | func_name = temp 363 | end 364 | 365 | if functions["gl"..func_name] then 366 | local arg_line = functions["gl"..func_name].arg_line or "" 367 | 368 | local arg_line1 = arg_line 369 | local arg_line2 = arg_line 370 | 371 | if name == "Texture" then 372 | arg_line1 = arg_line:replace("target, ", ""):replace("target", "") 373 | arg_line2 = arg_line:replace("target", "self.target") 374 | else 375 | arg_line1 = arg_line1:replace(name:lower() .. ", ", "") 376 | arg_line2 = arg_line2:replace(name:lower(), "self.id") 377 | end 378 | 379 | if object_info.functions then 380 | local info = object_info.functions[func_name] 381 | 382 | if info then 383 | if info.static_arguments then 384 | local tbl = (arg_line2 .. ","):split(",") 385 | for i,v in ipairs(info.static_arguments) do 386 | tbl[i] = serializer.GetLibrary("luadata").ToString(v) 387 | end 388 | arg_line2 = table.concat(tbl, ", "):sub(0,-3) 389 | end 390 | arg_line1 = info.arg_line1 or arg_line1 391 | arg_line2 = info.arg_line2 or arg_line2 392 | end 393 | end 394 | 395 | if friendly == "Image2D" then 396 | print(func_name, arg_line2) 397 | end 398 | 399 | insert("\t\t\tfunction META:" .. friendly .. "(" .. arg_line1 .. ")") 400 | if name == "Framebuffer" then 401 | if arg_line2:find("target") then 402 | insert("\t\t\t\tbind(self, target) return gl." .. func_name .. "(" .. arg_line2 .. ")") 403 | else 404 | insert("\t\t\t\tbind(self, \"GL_FRAMEBUFFER\") return gl." .. func_name .. "(" .. arg_line2 .. ")") 405 | end 406 | else 407 | insert("\t\t\t\tbind(self) return gl." .. func_name .. "(" .. arg_line2 .. ")") 408 | end 409 | insert"\t\t\tend" 410 | end 411 | end 412 | 413 | if name == "Texture" then 414 | insert"\t\t\tlocal ctype = ffi.typeof('struct { int id, target; }')" 415 | insert"\t\t\tffi.metatype(ctype, META)" 416 | insert"\t\t\tlocal temp = ffi.new('GLuint[1]')" 417 | insert"\t\t\tfunction META:Delete()" 418 | insert"\t\t\t\ttemp[0] = self.id" 419 | insert("\t\t\t\tgl.Delete"..name.."s(1, temp)") 420 | insert"\t\t\tend" 421 | insert"\t\t\tMETA.not_dsa = true" 422 | insert("\t\t\tfunction gl.Create"..name.."(target)") 423 | insert"\t\t\t\tlocal self = setmetatable({}, META)" 424 | insert("\t\t\t\tself.id = gl.Gen"..name.."()") 425 | insert"\t\t\t\tself.target = target" 426 | insert"\t\t\t\treturn self" 427 | insert"\t\t\tend" 428 | else 429 | insert"\t\t\tlocal ctype = ffi.typeof('struct { int id; }')" 430 | insert"\t\t\tffi.metatype(ctype, META)" 431 | insert"\t\t\tlocal temp = ffi.new('GLuint[1]')" 432 | insert"\t\t\tfunction META:Delete()" 433 | insert"\t\t\t\ttemp[0] = self.id" 434 | insert("\t\t\t\tgl.Delete"..name.."s(1, temp)") 435 | insert"\t\t\tend" 436 | insert"\t\t\tMETA.not_dsa = true" 437 | insert("\t\t\tfunction gl.Create"..name.."()") 438 | insert"\t\t\t\tlocal self = setmetatable({}, META)" 439 | insert("\t\t\t\tself.id = gl.Gen"..name.."()") 440 | insert"\t\t\t\treturn self" 441 | insert"\t\t\tend" 442 | end 443 | insert"\t\tend" 444 | insert"\tend" 445 | end 446 | end 447 | 448 | insert("end") 449 | 450 | insert("gl.e = setmetatable({}, {__index = function(_, key) return tonumber(ffi.cast(\"GL_LUA_ENUMS\", key)) end})") 451 | 452 | insert("return gl") 453 | --collectgarbage() 454 | local code = table.concat(lua, "\n") 455 | vfs.Write("lua/libraries/graphics/ffi/opengl/init.lua", code) 456 | 457 | --package.loaded["graphics.ffi.opengl"] = nil 458 | --require("graphics.ffi.opengl") 459 | -------------------------------------------------------------------------------- /opengl/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /opengl/readme.md: -------------------------------------------------------------------------------- 1 | #TODO 2 | 3 | This doesn't really use ffibuild, it uses gl.xml and libopengl.lua has been heavily modified after build.lua was run to emulalte direct state access. This is here just for consistency in my own projects. 4 | -------------------------------------------------------------------------------- /openssl/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | ffibuild.NixBuild({ 5 | package_name = "openssl", 6 | library_name = "libssl" 7 | }) 8 | -------------------------------------------------------------------------------- /openssl/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /purple/Makefile: -------------------------------------------------------------------------------- 1 | PLUGIN_NAME = goura 2 | PLUGIN_DIR = $(HOME)/.purple/plugins 3 | PLUGIN_HEADER = libpurple.lua 4 | 5 | LUA_DIR = ../luajit/repo/ 6 | LUA_BIN = src/luajit 7 | LUA_CFLAGS = -I$(LUA_DIR)/src 8 | LUA_LIBS = -L$(LUA_DIR)/src -lluajit 9 | LUA_BUILD = build.lua 10 | 11 | CC := gcc 12 | PURPLE_CFLAGS = $(shell pkg-config purple --cflags) 13 | PURPLE_LIBS = $(shell pkg-config purple --libs) 14 | 15 | all: $(PLUGIN_HEADER) 16 | 17 | install: $(PLUGIN_HEADER) 18 | mkdir -p $(PLUGIN_DIR) 19 | cp $(PLUGIN_NAME).so $(PLUGIN_DIR) 20 | 21 | mkdir -p $(PLUGIN_DIR)/$(PLUGIN_NAME) 22 | cp *.lua $(PLUGIN_DIR)/$(PLUGIN_NAME) 23 | 24 | cp ./$(LUA_DIR)/$(LUA_BIN)/libluajit.so $(PLUGIN_DIR)/$(PLUGIN_NAME) 25 | 26 | $(PLUGIN_HEADER): $(PLUGIN_NAME).so 27 | ./$(LUA_DIR)/$(LUA_BIN) $(LUA_BUILD) 28 | 29 | $(PLUGIN_NAME).so: $(PLUGIN_NAME).o 30 | $(CC) -shared $(PLUGIN_NAME).o -o $(PLUGIN_NAME).so -Wl,--whole-archive $(LUA_LIBS) -Wl,--no-whole-archive $(PURPLE_LIBS) 31 | 32 | $(PLUGIN_NAME).o: $(LUA_DIR) 33 | $(CC) $(CFLAGS) -fPIC -c $(PLUGIN_NAME).c -o $(PLUGIN_NAME).o $(LUA_CFLAGS) $(PURPLE_CFLAGS) -DHAVE_CONFIG_H 34 | 35 | $(LUA_DIR): 36 | cd ../../ && make LuaJIT 37 | 38 | clean: 39 | rm -rf *.o *.c~ *.h~ *.so *.la .libs $(PLUGIN_HEADER) 40 | 41 | uninstall: 42 | rm -rf $(PLUGIN_DIR)/$(PLUGIN_NAME) 43 | rm -rf $(PLUGIN_DIR)/$(PLUGIN_NAME).so 44 | 45 | run: 46 | make install && pidgin 47 | -------------------------------------------------------------------------------- /purple/README.md: -------------------------------------------------------------------------------- 1 | Adds a plugin called goura to pidgin and exposes the entire libpurple api to lua. Note that in the upcoming pidgin 3 there's going to be an offical lua api using https://bitbucket.org/gplugin/main 2 | 3 | When the plugin is enabled it adds a command "!l" to chat and exposes _G.purple. If you trust a friend to execute code on your computer with !l you can make a group called lua and add them there. 4 | 5 | This is just something I personally wanted and so the !l command serves more as example usage. I don't know what else to do with this. Modify main.lua to do what you want. 6 | -------------------------------------------------------------------------------- /purple/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") 3 | 4 | local header = ffibuild.ProcessSourceFileGCC([[ 5 | #define PURPLE_PLUGINS 6 | #include 7 | ]], "$(pkg-config --cflags purple)") 8 | 9 | local meta_data = ffibuild.GetMetaData(header) 10 | local header = meta_data:BuildMinimalHeader(function(name) return name:find("^purple_") end, function(name) return name:find("PURPLE_") or name:find("XMLNODE_") end, true) 11 | 12 | local lua = ffibuild.StartLibrary(header, "metatables", "chars_to_string") 13 | 14 | lua = lua .. [[ 15 | local function glist_to_table(l, meta_name) 16 | if not metatables[meta_name] then 17 | error((meta_name or "nil") .. " is not a valid meta type", 3) 18 | end 19 | 20 | local out = {} 21 | 22 | for i = 1, math.huge do 23 | out[i] = ffi.cast(metatables[meta_name].ctype, l.data) 24 | out[i] = wrap_pointer(out[i], meta_name) 25 | l = l.next 26 | if l == nil then 27 | break 28 | end 29 | end 30 | 31 | return out 32 | end 33 | 34 | ffi.cdef("struct _GList * g_list_insert(struct _GList *, void *, int);\nstruct _GList * g_list_alloc();") 35 | 36 | local function table_to_glist(tbl) 37 | local list = CLIB.g_list_alloc() 38 | for i, v in ipairs(tbl) do 39 | CLIB.g_list_insert(list, v.ptr, -1) 40 | end 41 | return list 42 | end 43 | 44 | ffi.cdef([==[ 45 | void *malloc(size_t size); 46 | void free(void *ptr); 47 | ]==]) 48 | 49 | local function replace_buffer(buffer, size, data) 50 | ffi.C.free(buffer[0]) 51 | local chr = ffi.C.malloc(size) 52 | ffi.copy(chr, data) 53 | buffer[0] = chr 54 | end 55 | 56 | local function create_boxed_table(p, wrap_in, wrap_out) 57 | return setmetatable({p = p}, {__newindex = function(s, k, v) wrap_in(s.p, v) end, __index = function(s, k) return wrap_out(s.p) end}) 58 | end 59 | ]] 60 | 61 | local objects = {} 62 | local libraries = {} 63 | 64 | local function argument_translate(declaration, name, type) 65 | if declaration == "sturct _GList *" or declaration == "struct _GList *" then 66 | return "table_to_glist(" .. name .. ")" 67 | elseif objects[type:GetBasicType(meta_data)] then 68 | return name .. ".ptr" 69 | end 70 | end 71 | 72 | local function return_translate(declaration, type) 73 | if declaration == "const char *" or declaration == "char *" then 74 | return "v = chars_to_string(v)" 75 | elseif declaration == "sturct _GList *" or declaration == "struct _GList *" then 76 | return "v = glist_to_table(v, cast_type)", function(s) return s:gsub("^(.-)%)", function(s) if s:find(",") then return s .. ", cast_type)" else return s .. "cast_type)" end end) end 77 | elseif objects[type:GetBasicType(meta_data)] then 78 | return "v = wrap_pointer(v, \"" .. objects[type:GetBasicType(meta_data)].meta_name .. "\")" 79 | end 80 | end 81 | 82 | do -- metatables 83 | local prefix_translate = { 84 | ssl_connection = {"ssl"}, 85 | conv_message = {"conversation_message"}, 86 | request_fields = {"request_fields", "request_field"}, 87 | srv_txt_query_data = {"srv_txt_query"}, 88 | theme_manager = {"theme_loader"}, 89 | stored_image = {"imgstore"}, 90 | conversation = {"conv"}, 91 | saved_status = {"savedstatus"}, 92 | } 93 | 94 | for _, info in ipairs(meta_data:GetStructTypes("^Purple(.+)")) do 95 | local basic_type = info.type:GetBasicType(meta_data) 96 | objects[basic_type] = {meta_name = info.name, declaration = info.type:GetDeclaration(meta_data), functions = {}} 97 | 98 | local prefix = ffibuild.ChangeCase(basic_type:match("^struct[%s_]-Purple(.+)"), "FooBar", "foo_bar") 99 | 100 | for func_name, func_info in pairs(meta_data:GetFunctionsStartingWithType(info.type)) do 101 | local friendly = func_name:match("purple_" .. prefix .. "_(.+)") 102 | 103 | if not friendly and prefix_translate[prefix] then 104 | for _, prefix in ipairs(prefix_translate[prefix]) do 105 | friendly = func_name:match("purple_" .. prefix .. "_(.+)") 106 | if friendly then break end 107 | end 108 | end 109 | 110 | if friendly then 111 | friendly = ffibuild.ChangeCase(friendly, "foo_bar", "FooBar") 112 | objects[basic_type].functions[friendly] = func_info 113 | func_info.done = true 114 | end 115 | end 116 | 117 | if not next(objects[basic_type].functions) then 118 | objects[basic_type] = nil 119 | end 120 | end 121 | 122 | for _, info in pairs(objects) do 123 | lua = lua .. meta_data:BuildLuaMetaTable(info.meta_name, info.declaration, info.functions, argument_translate, return_translate) 124 | end 125 | end 126 | 127 | do -- libraries 128 | for func_name, type in pairs(meta_data.functions) do 129 | if not type.done and func_name:find("^purple_") then 130 | local library_name, friendly_name = func_name:match("purple_(.-)_(.+)") 131 | 132 | if not library_name then 133 | library_name = "purple" 134 | friendly_name = func_name:match("purple_(.+)") 135 | end 136 | 137 | friendly_name = ffibuild.ChangeCase(friendly_name, "foo_bar", "FooBar") 138 | 139 | libraries[library_name] = libraries[library_name] or {} 140 | libraries[library_name][friendly_name] = type 141 | end 142 | end 143 | 144 | for library_name, functions in pairs(libraries) do 145 | lua = lua .. "library." .. library_name .. " = {\n" 146 | for friendly_name, func_type in pairs(functions) do 147 | lua = lua .. "\t" .. friendly_name .. " = " .. meta_data:BuildLuaFunction(func_type.name, func_type, argument_translate, return_translate) .. ",\n" 148 | end 149 | lua = lua .. "}\n" 150 | end 151 | end 152 | 153 | do -- callbacks 154 | lua = lua .. "local callbacks = {}\n" 155 | 156 | local callbacks_meta_data = ffibuild.GetMetaData(dofile("callbacks.lua")) 157 | 158 | for func_name, func_type in pairs(callbacks_meta_data.functions) do 159 | local arg_line = {} 160 | local wrap_line = {} 161 | 162 | if func_type.arguments then 163 | for i, arg in ipairs(func_type.arguments) do 164 | local decl = arg:GetDeclaration(meta_data) 165 | 166 | if decl == "const char *" or decl == "char *" then 167 | wrap_line[i] = "chars_to_string(_"..i..")" 168 | elseif decl == "sturct _GList *" or decl == "struct _GList *" then 169 | wrap_line[i] = "glist_to_table(_"..i..", 'void *')" 170 | elseif decl == "struct GList * *"then 171 | wrap_line[i] = "create_boxed_table(_"..i..", function(p, v) p[0] = table_to_glist(v) end, function(p) return glist_to_table(p[0]) end)" 172 | elseif decl == "char * *" then 173 | wrap_line[i] = "create_boxed_table(_"..i..", function(p, v) replace_buffer(p, #v, v) end, function(p) return ffi.string(p[0]) end)" 174 | elseif objects[arg:GetBasicType(meta_data)] then 175 | wrap_line[i] = "wrap_pointer(_"..i..", \"" .. objects[arg:GetBasicType(meta_data)].meta_name .. "\")" 176 | else 177 | wrap_line[i] = "_" .. i .. " --[["..decl.."]] " 178 | end 179 | 180 | arg_line[i] = "_" .. i 181 | end 182 | end 183 | 184 | table.insert(arg_line, 1, "callback") 185 | 186 | arg_line = table.concat(arg_line, ", ") 187 | wrap_line = table.concat(wrap_line, ", ") 188 | 189 | local ret_line = "return ret" 190 | 191 | if func_type.return_type:GetBasicType(meta_data) ~= "void" then 192 | ret_line = " if ret == nil then return ffi.new(\"" .. func_type.return_type:GetBasicType(meta_data) .. "\") end " .. ret_line 193 | end 194 | 195 | lua = lua .. "callbacks[\"" .. func_name:gsub("_", "-") .. "\"] = {\n" 196 | lua = lua .. "\twrap = function(" .. arg_line .. ") local ret = callback(" .. wrap_line .. ") " .. ret_line .. " end,\n" 197 | lua = lua .. "\tdefinition = \"" .. func_type:GetDeclaration(meta_data, "*", "") .. "\",\n" 198 | lua = lua .. "}\n" 199 | end 200 | 201 | lua = lua .. [[ 202 | library.signal.Connect_real = library.signal.Connect 203 | 204 | function library.signal.Connect(signal, callback) 205 | if not library.handles then error("unable to find handles (use purple.set_handles(plugin_handle, conversation_handle))", 2) end 206 | 207 | local info = callbacks[signal] 208 | 209 | if not info then error(signal .. " is not a valid signal!") end 210 | 211 | return library.signal.Connect_real(library.handles.conversation, signal, library.handles.plugin, ffi.cast("void(*)()", ffi.cast(info.definition, function(...) 212 | local ok, ret = pcall(info.wrap, callback, ...) 213 | 214 | if not ok then 215 | library.notify.Message(library.handles.plugin, "notify_msg_info", "lua error", signal, ret, nil, nil) 216 | return default_value 217 | end 218 | 219 | return ret 220 | end)), nil) 221 | end 222 | 223 | function library.set_handles(plugin, conv) 224 | library.handles = { 225 | plugin = ffi.cast("struct _PurplePlugin *", plugin), 226 | conversation = conv, 227 | } 228 | end 229 | 230 | ]] 231 | end 232 | 233 | ffibuild.EndLibrary(lua, header) 234 | -------------------------------------------------------------------------------- /purple/callbacks.lua: -------------------------------------------------------------------------------- 1 | -- these have been auto generated but you can add your own if you follow this convention. 2 | -- buddy_privacy_changed will become buddy-privacy-changed 3 | 4 | return [[void buddy_status_changed ( PurpleBuddy * , PurpleStatus * , PurpleStatus * ); 5 | void buddy_privacy_changed ( PurpleBuddy * ); 6 | void buddy_idle_changed ( PurpleBuddy * , int , int ); 7 | void buddy_signed_on ( PurpleBuddy * ); 8 | void buddy_signed_off ( PurpleBuddy * ); 9 | void buddy_got_login_time ( PurpleBuddy * ); 10 | void blist_node_added ( PurpleBlistNode * ); 11 | void blist_node_removed ( PurpleBlistNode * ); 12 | void buddy_added ( PurpleBuddy * ); 13 | void buddy_removed ( PurpleBuddy * ); 14 | void buddy_icon_changed ( PurpleBuddy * ); 15 | void update_idle ( ); 16 | void blist_node_extended_menu ( PurpleBlistNode * , GList * * ); 17 | void blist_node_aliased ( PurpleBlistNode * , const char * ); 18 | void buddy_caps_changed ( PurpleBuddy * , int , int ); 19 | void certificate_stored ( PurpleCertificatePool * , const char * ); 20 | void certificate_deleted ( PurpleCertificatePool * , const char * ); 21 | void cipher_added ( PurpleCipher * ); 22 | void cipher_removed ( PurpleCipher * ); 23 | void cmd_added ( const char * , int , int ); 24 | void cmd_removed ( const char * ); 25 | bool writing_im_msg ( PurpleAccount * , const char * , char * * , PurpleConversation * , unsigned int ); 26 | void wrote_im_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , unsigned int ); 27 | void sent_attention ( PurpleAccount * , const char * , PurpleConversation * , unsigned int ); 28 | void got_attention ( PurpleAccount * , const char * , PurpleConversation * , unsigned int ); 29 | void sending_im_msg ( PurpleAccount * , const char * , char * * ); 30 | void sent_im_msg ( PurpleAccount * , const char * , const char * ); 31 | bool receiving_im_msg ( PurpleAccount * , char * * , char * * , PurpleConversation * , unsigned int * ); 32 | void received_im_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , unsigned int ); 33 | void blocked_im_msg ( PurpleAccount * , const char * , const char * , unsigned int , unsigned int ); 34 | bool writing_chat_msg ( PurpleAccount * , const char * , char * * , PurpleConversation * , unsigned int ); 35 | void wrote_chat_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , unsigned int ); 36 | void sending_chat_msg ( PurpleAccount * , char * * , unsigned int ); 37 | void sent_chat_msg ( PurpleAccount * , const char * , unsigned int ); 38 | bool receiving_chat_msg ( PurpleAccount * , char * * , char * * , PurpleConversation * , unsigned int * ); 39 | void received_chat_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , unsigned int ); 40 | void conversation_created ( PurpleConversation * ); 41 | void conversation_updated ( PurpleConversation * , unsigned int ); 42 | void deleting_conversation ( PurpleConversation * ); 43 | void buddy_typing ( PurpleAccount * , const char * ); 44 | void buddy_typed ( PurpleAccount * , const char * ); 45 | void buddy_typing_stopped ( PurpleAccount * , const char * ); 46 | bool chat_buddy_joining ( PurpleConversation * , const char * , unsigned int ); 47 | void chat_buddy_joined ( PurpleConversation * , const char * , unsigned int , bool ); 48 | void chat_buddy_flags ( PurpleConversation * , const char * , unsigned int , unsigned int ); 49 | bool chat_buddy_leaving ( PurpleConversation * , const char * , const char * ); 50 | void chat_buddy_left ( PurpleConversation * , const char * , const char * ); 51 | void deleting_chat_buddy ( PurpleConvChatBuddy * ); 52 | void chat_inviting_user ( PurpleConversation * , const char * , char * * ); 53 | void chat_invited_user ( PurpleConversation * , const char * , const char * ); 54 | int chat_invited ( PurpleAccount * , const char * , const char * , const char * , void * ); 55 | void chat_invite_blocked ( PurpleAccount * , const char * , const char * , const char * , GHashTable * ); 56 | void chat_joined ( PurpleConversation * ); 57 | void chat_join_failed ( PurpleConnection * , void * ); 58 | void chat_left ( PurpleConversation * ); 59 | void chat_topic_changed ( PurpleConversation * , const char * , const char * ); 60 | void cleared_message_history ( PurpleConversation * ); 61 | void conversation_extended_menu ( PurpleConversation * , GList * * ); 62 | bool uri_handler ( const char * , const char * , GHashTable * ); 63 | void quitting ( ); 64 | bool dbus_method_called ( void * , void * ); 65 | void dbus_introspect ( void * * ); 66 | void file_recv_accept ( PurpleXfer * ); 67 | void file_send_accept ( PurpleXfer * ); 68 | void file_recv_start ( PurpleXfer * ); 69 | void file_send_start ( PurpleXfer * ); 70 | void file_send_cancel ( PurpleXfer * ); 71 | void file_recv_cancel ( PurpleXfer * ); 72 | void file_send_complete ( PurpleXfer * ); 73 | void file_recv_complete ( PurpleXfer * ); 74 | void file_recv_request ( PurpleXfer * ); 75 | void image_deleting ( PurpleStoredImage * ); 76 | const char * log_timestamp ( PurpleLog * , int , int64_t , bool ); 77 | void displaying_email_notification ( const char * , const char * , const char * , const char * ); 78 | void displaying_emails_notification ( void * , void * , void * , void * , unsigned int ); 79 | void displaying_userinfo ( PurpleAccount * , const char * , PurpleNotifyUserInfo * ); 80 | void plugin_load ( PurplePlugin * ); 81 | void plugin_unload ( PurplePlugin * ); 82 | void savedstatus_changed ( PurpleSavedStatus * , PurpleSavedStatus * ); 83 | void savedstatus_added ( PurpleSavedStatus * ); 84 | void savedstatus_deleted ( PurpleSavedStatus * ); 85 | void savedstatus_modified ( PurpleSavedStatus * ); 86 | bool playing_sound_event ( int , PurpleAccount * ); 87 | void account_modified ( PurpleAccount * ); 88 | void gtkblist_hiding ( PurpleBuddyList * ); 89 | void gtkblist_unhiding ( PurpleBuddyList * ); 90 | void gtkblist_created ( PurpleBuddyList * ); 91 | void drawing_tooltip ( PurpleBlistNode * , GString * , bool ); 92 | const char * drawing_buddy ( PurpleBuddy * ); 93 | const char * conversation_timestamp ( PurpleConversation * , int , int64_t , bool ); 94 | bool displaying_im_msg ( PurpleAccount * , const char * , char * * , PurpleConversation * , int ); 95 | void displayed_im_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , int ); 96 | bool displaying_chat_msg ( PurpleAccount * , const char * , char * * , PurpleConversation * , int ); 97 | void displayed_chat_msg ( PurpleAccount * , const char * , const char * , PurpleConversation * , int ); 98 | void conversation_switched ( PurpleConversation * ); 99 | bool chat_nick_autocomplete ( PurpleConversation * ); 100 | bool chat_nick_clicked ( PurpleConversation * , const char * , unsigned int ); 101 | ]] -------------------------------------------------------------------------------- /purple/goura.c: -------------------------------------------------------------------------------- 1 | #define PLUGIN_NAME "goura" 2 | #define PLUGIN_VERSION "0.1.0" 3 | #define PLUGIN_SUMMARY "lua for pidgin" 4 | #define PLUGIN_DESCRIPTION "place scripts in ~.purple/"PLUGIN_NAME"/" 5 | #define PLUGIN_WEBSITE "https://github.com/CapsAdmin/"PLUGIN_NAME 6 | #define PLUGIN_AUTHOR "CapsAdmin" 7 | 8 | #define PLUGIN_DIR ".purple/plugins/"PLUGIN_NAME 9 | #define PLUGIN_MAIN_LUA "main.lua" 10 | 11 | #define PLUGIN_ID PLUGIN_NAME"-boopboop" 12 | 13 | //Purple plugin 14 | #define PURPLE_PLUGINS 15 | #include 16 | 17 | //Lua Libraries 18 | #include 19 | #include 20 | #include 21 | 22 | lua_State *L = NULL; 23 | 24 | void error(PurplePlugin *plugin, const char *type, const char *reason) 25 | { 26 | purple_notify_warning(plugin, PLUGIN_NAME, "compile error", lua_tostring(L, -1)); 27 | purple_debug_warning(PLUGIN_NAME " lua error", "%s: %s", type, reason); 28 | } 29 | 30 | static gboolean plugin_load(PurplePlugin *plugin) 31 | { 32 | L = luaL_newstate(); 33 | luaL_openlibs(L); 34 | 35 | char lua_path[512]; 36 | sprintf(lua_path, "%s/%s/%s", g_get_home_dir(), PLUGIN_DIR, PLUGIN_MAIN_LUA); 37 | 38 | if (luaL_loadfile(L, lua_path)) 39 | { 40 | error(plugin, "compile error", lua_tostring(L, -1)); 41 | 42 | lua_close(L); 43 | return FALSE; 44 | } 45 | 46 | void *conv = purple_conversations_get_handle(); 47 | 48 | lua_pushstring(L, lua_path); 49 | lua_pushlightuserdata(L, plugin); 50 | lua_pushlightuserdata(L, conv); 51 | 52 | if (lua_pcall(L, 3, 0, 0)) 53 | { 54 | error(plugin, "runtime error", lua_tostring(L, -1)); 55 | 56 | lua_close(L); 57 | return FALSE; 58 | } 59 | 60 | return TRUE; 61 | } 62 | 63 | static gboolean plugin_unload(PurplePlugin *plugin) 64 | { 65 | lua_close(L); 66 | L = NULL; 67 | 68 | return TRUE; 69 | } 70 | 71 | static PurplePluginInfo info = { 72 | PURPLE_PLUGIN_MAGIC, 73 | PURPLE_MAJOR_VERSION, 74 | PURPLE_MINOR_VERSION, 75 | PURPLE_PLUGIN_STANDARD, 76 | NULL, 77 | 0, 78 | NULL, 79 | PURPLE_PRIORITY_DEFAULT, 80 | PLUGIN_ID, 81 | PLUGIN_NAME, 82 | PLUGIN_VERSION, 83 | PLUGIN_SUMMARY, 84 | PLUGIN_DESCRIPTION, 85 | PLUGIN_AUTHOR, 86 | PLUGIN_WEBSITE, 87 | plugin_load, 88 | plugin_unload, 89 | NULL, 90 | NULL, 91 | NULL, 92 | NULL, 93 | NULL, 94 | NULL, 95 | NULL, 96 | NULL, 97 | NULL 98 | }; 99 | 100 | static void init_plugin(PurplePlugin * plugin) {} 101 | 102 | PURPLE_INIT_PLUGIN(autorespond, init_plugin, info) 103 | -------------------------------------------------------------------------------- /purple/main.lua: -------------------------------------------------------------------------------- 1 | local path, plugin_handle, conv_handle = ... 2 | local plugin_dir = path:gsub("/main.lua", "") 3 | 4 | package.path = package.path .. ";" .. plugin_dir .. "/?.lua" 5 | 6 | local ffi = require("ffi") 7 | local purple = require("libpurple") 8 | purple.set_handles(plugin_handle, conv_handle) 9 | 10 | do -- extended 11 | purple.buddy_list = purple.blist 12 | purple.blist = nil 13 | 14 | function purple.buddy_list.FindByName(name) 15 | for _, buddy in ipairs(purple.buddy_list.GetBuddies("buddy")) do 16 | if buddy:GetName() == name then 17 | return buddy 18 | end 19 | end 20 | end 21 | end 22 | 23 | do 24 | local easylua = {} 25 | 26 | local commands = {} 27 | 28 | commands.l = { 29 | help = "run lua", 30 | callback = function(...) 31 | return easylua.RunLua(...) 32 | end, 33 | } 34 | 35 | commands.print = { 36 | help = "print lua", 37 | callback = function(code, ...) 38 | return easylua.RunLua("print(" .. code .. ")", ...) 39 | end, 40 | } 41 | 42 | local function msg(str, account, who) 43 | purple.conversation.New("PURPLE_CONV_TYPE_IM", account, who):GetImData():Send(str) 44 | end 45 | 46 | function easylua.RunString(msg, account, who) 47 | local name, cmd = msg:match("^!(.-)%s+(.+)$") 48 | 49 | if commands[name] then 50 | easylua.PCall( 51 | commands[name].callback, account, who, 52 | cmd, account, who 53 | ) 54 | end 55 | end 56 | 57 | function easylua.PCall(func, account, who, ...) 58 | local ret = {pcall(func, ...)} 59 | if ret[1] then 60 | table.remove(ret, 1) 61 | if #ret > 0 then 62 | for i, v in ipairs(ret) do 63 | ret[i] = tostring(v) 64 | end 65 | 66 | msg(table.concat(ret, ", ")) 67 | end 68 | else 69 | msg(tostring(ret[2]), account, who) 70 | end 71 | end 72 | 73 | function easylua.RunLua(code, account, who) 74 | local env = { 75 | {"buddy", purple.find.Buddy(account, who)}, 76 | {"who", who}, 77 | {"account", account}, 78 | {"print", function(...) 79 | local args = {} 80 | for i = 1, select("#", ...) do 81 | local val = (select(i, ...)) 82 | if type(val) == "cdata" and tostring(ffi.typeof(val)):find("char") then 83 | val = purple.chars_to_string(val) 84 | else 85 | val = tostring(val) 86 | end 87 | table.insert(args, val) 88 | end 89 | msg(table.concat(args, ", "), account, who) 90 | end}, 91 | } 92 | 93 | local locals = "local " 94 | for i, data in ipairs(env) do 95 | locals = locals .. data[1] 96 | if i ~= #env then 97 | locals = locals .. ", " 98 | end 99 | end 100 | 101 | local func = assert(loadstring(locals .. " = ... " .. code, code)) 102 | 103 | local vars = {} 104 | for _, data in ipairs(env) do 105 | table.insert(vars, data[2]) 106 | end 107 | 108 | return func(unpack(vars)) 109 | end 110 | 111 | purple.signal.Connect("sent-im-msg", function(account, who, message) 112 | easylua.RunString(purple.markup.StripHtml(message), account, who) 113 | 114 | return false 115 | end) 116 | 117 | purple.signal.Connect("received-im-msg", function(account, who, message, conv, flags) 118 | local buddy = purple.find.Buddy(account, who) 119 | 120 | if buddy:GetGroup():GetName() == "lua" then 121 | easylua.RunString(purple.markup.StripHtml(message), account, who, conv) 122 | end 123 | end) 124 | end 125 | 126 | _G.purple = purple 127 | _G.ffi = ffi 128 | 129 | do 130 | purple.signal.Connect("received-im-msg", function(account, who, buffer, conv, flags) 131 | local buddy = purple.find.Buddy(account, who) 132 | local presence = buddy:GetPresence() 133 | 134 | local msg = {} 135 | msg.text = purple.markup.StripHtml(buffer) 136 | msg.remote_username = who 137 | msg.local_alias = account:GetAlias() 138 | msg.local_username = account:GetNameForDisplay() 139 | msg.remote_alias = buddy:GetAlias() 140 | msg.protocol_id = account:GetProtocolId() 141 | 142 | local group = buddy:GetGroup() 143 | 144 | if group.ptr ~= nil then 145 | msg.remote_from_group = group:GetName() 146 | end 147 | 148 | local local_status = account:GetActiveStatus() 149 | local local_status_type = local_status:GetType() 150 | 151 | msg.local_status_id = purple.primitive.GetIdFromType(local_status_type:GetPrimitive()) 152 | if local_status_type:GetAttr("message") ~= nil then 153 | msg.local_status_msg = local_status:GetAttrString("message") 154 | else 155 | local savedstatus = savedstatus.GetCurrnet() 156 | if savedstatus.ptr ~= nil then 157 | msg.local_status_msg = savedstatus:GetMessage() 158 | end 159 | end 160 | 161 | local remote_status = presence:GetActiveStatus() 162 | local remote_status_type = remote_status:GetType() 163 | 164 | msg.remote_status_id = purple.primitive.GetIdFromType(remote_status_type:GetPrimitive()) 165 | 166 | if remote_status_type:GetAttr("message") ~= nil then 167 | msg.local_status_msg = remote_status:GetAttrString("message") 168 | else 169 | msg.local_status_msg = nil 170 | end 171 | 172 | for k,v in pairs(msg) do 173 | print(k .. " = " .. tostring(v)) 174 | end 175 | end) 176 | end 177 | 178 | do 179 | purple.signal.Connect("writing-im-msg", function(account, who, buffer, conv, flags) 180 | if buffer.str == "wow" then 181 | buffer.str = "bubu: SYSWOW32" 182 | end 183 | end) 184 | end -------------------------------------------------------------------------------- /purple/temp.c: -------------------------------------------------------------------------------- 1 | #define PURPLE_PLUGINS 2 | #include 3 | -------------------------------------------------------------------------------- /steamworks/build.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path .. ";../?.lua" 2 | local ffibuild = require("ffibuild") -------------------------------------------------------------------------------- /steamworks/build_from_json.lua: -------------------------------------------------------------------------------- 1 | if not vfs.IsFile("steam_api.json") then 2 | error("please put steam_api.json in your data folder (" .. R("data/") .. "steam_api.json") 3 | end 4 | 5 | local ffi = require("ffi") 6 | local prepend = "SteamWorks_" 7 | local blacklist = { 8 | ["CSteamAPIContext"] = true, 9 | ["CCallbackBase"] = true, 10 | ["CCallback"] = true, 11 | ["CCallResult"] = true, 12 | ["CCallResult::func_t"] = true, 13 | ["CCallback::func_t"] = true, 14 | } 15 | local json = serializer.ReadFile("json", "steam_api.json") 16 | 17 | local interfaces = {} 18 | 19 | local header = {} 20 | local i = 1 21 | local a = function(s, ...) header[i] = s:format(...) i = i + 1 end 22 | 23 | if false then -- consts 24 | for i, info in ipairs(json.consts) do 25 | a("static const %s %s = %s;", info.consttype, prepend .. info.constname, info.constval) 26 | end 27 | end 28 | 29 | do -- enums 30 | for group, info in ipairs(json.enums) do 31 | info.enumname = prepend .. info.enumname:gsub("::", "_") 32 | 33 | a("typedef enum %s {", info.enumname) 34 | for i,v in ipairs(info.values) do 35 | a("\t%s = %s%s", v.name, v.value, i == #info.values and "" or ",") 36 | end 37 | a("} %s;", info.enumname) 38 | end 39 | end 40 | 41 | do -- typedefs 42 | local done = {} 43 | 44 | for i, info in ipairs(json.typedefs) do 45 | if not blacklist[info.typedef] then 46 | info.type = info.type:gsub("%[.-%]", "*") 47 | if info.type:find("(*)", nil, true) then 48 | local line = info.type:gsub("%(%*%)", function() return "(*" .. prepend .. info.typedef .. ")" end) 49 | 50 | line = line:gsub("__attribute__%(%(cdecl%)%)", "") 51 | line = line:gsub("SteamAPICall_t", prepend .. "SteamAPICall_t") 52 | line = line:gsub("uint32", prepend .. "uint32") 53 | 54 | a("typedef %s;", line) 55 | else 56 | if not info.type:startswith("struct") and not info.type:startswith("union") and not pcall(ffi.typeof, info.type) then info.type = prepend .. info.type end 57 | 58 | local typedef = info.typedef 59 | typedef = typedef:gsub("::SteamCallback_t", "") 60 | 61 | a("typedef %s %s;", info.type, prepend .. typedef) 62 | end 63 | end 64 | end 65 | 66 | for i, info in ipairs(json.structs) do 67 | if info.struct == "CSteamAPIContext" then 68 | for i,v in ipairs(info.fields) do 69 | v.fieldtype = v.fieldtype:gsub("class ", "") 70 | v.fieldtype = v.fieldtype:sub(0,-3) 71 | interfaces[v.fieldtype] = v.fieldtype:sub(2) 72 | v.fieldtype = prepend .. v.fieldtype 73 | a("typedef struct %s {} %s;", v.fieldtype, v.fieldtype) 74 | end 75 | end 76 | end 77 | 78 | --a("typedef struct %s {} %s;", prepend .. "ISteamClient", prepend .. "ISteamClient") 79 | a("typedef struct %s {} %s;", prepend .. "ISteamGameServer", prepend .. "ISteamGameServer") 80 | a("typedef struct %s {} %s;", prepend .. "ISteamGameServerStats", prepend .. "ISteamGameServerStats") 81 | a("typedef struct %s {} %s;", prepend .. "ISteamMatchmakingServerListResponse", prepend .. "ISteamMatchmakingServerListResponse") 82 | a("typedef struct %s {} %s;", prepend .. "ISteamMatchmakingPlayersResponse", prepend .. "ISteamMatchmakingPlayersResponse") 83 | a("typedef struct %s {} %s;", prepend .. "ISteamMatchmakingPingResponse", prepend .. "ISteamMatchmakingPingResponse") 84 | a("typedef struct %s {} %s;", prepend .. "ISteamMatchmakingRulesResponse", prepend .. "ISteamMatchmakingRulesResponse") 85 | end 86 | 87 | do -- structs 88 | -- CGame Fix 89 | for i,v in ipairs(json.structs) do 90 | if v.struct == "CGameID::(anonymous)" then 91 | table.remove(json.structs, i) 92 | table.insert(json.structs, i - 1, v) 93 | v.struct = "CGameID" 94 | v.fields[2].fieldtype = "struct GameID_t" 95 | end 96 | end 97 | 98 | -- vr:: Fix 99 | for i,v in pairs(json.structs) do 100 | if v.struct:find("vr::") then 101 | json.structs[i] = nil 102 | end 103 | end 104 | table.fixindices(json.structs) 105 | 106 | local function add_fields(info, level) 107 | for _, field in pairs(info.fields) do 108 | field.fieldtype = field.fieldtype:gsub("class ", "struct ") 109 | field.fieldtype = field.fieldtype:gsub("enum ", "") 110 | 111 | local size = field.fieldtype:match("(%[.-%])") 112 | if size then 113 | field.fieldtype = field.fieldtype:gsub(" (%[.-%])", "") 114 | field.fieldname = field.fieldname .. size 115 | end 116 | 117 | local type, name = field.fieldtype:match("(.+) (.+)") 118 | if type == "struct" or type == "union" then 119 | a("%s%s {", ("\t"):rep(level), type) 120 | local struct = info.struct 121 | for _, info in pairs(json.structs) do 122 | if info.struct:startswith(struct) then 123 | local struct = info.struct:gsub(struct .. "::", "") 124 | if struct:startswith(name) then 125 | add_fields(info, level + 1) 126 | json.structs[_] = nil 127 | end 128 | end 129 | end 130 | a("%s} %s;", ("\t"):rep(level), field.fieldname) 131 | else 132 | if not pcall(ffi.typeof, field.fieldtype) then field.fieldtype = prepend .. field.fieldtype end 133 | a("%s%s %s;", ("\t"):rep(level), field.fieldtype, field.fieldname) 134 | end 135 | end 136 | end 137 | 138 | for i, info in pairs(json.structs) do 139 | if not blacklist[info.struct] then 140 | a("typedef struct %s {", prepend .. info.struct) 141 | add_fields(info, 1) 142 | a("} %s;", prepend .. info.struct) 143 | end 144 | end 145 | end 146 | 147 | do -- methods 148 | for i, info in ipairs(json.methods) do 149 | if not info.classname:find("::", nil, true) then 150 | local args = "(" 151 | 152 | args = args .. prepend .. info.classname .. "* self" 153 | 154 | if info.params then 155 | args = args .. ", " 156 | for i, arg in ipairs(info.params) do 157 | arg.paramtype = arg.paramtype:gsub("class ", "") 158 | arg.paramtype = arg.paramtype:gsub("struct ", "") 159 | if arg.paramtype ~= "const char *" then arg.paramtype = arg.paramtype:gsub("const ", "") end 160 | arg.paramtype = arg.paramtype:gsub("::", "_") 161 | 162 | if not pcall(ffi.typeof, arg.paramtype) then arg.paramtype = prepend .. arg.paramtype end 163 | 164 | args = args .. ("%s %s%s"):format(arg.paramtype, arg.paramname, i == #info.params and "" or ", ") 165 | end 166 | end 167 | args = args .. ")" 168 | 169 | info.returntype = info.returntype:gsub("class ", "") 170 | 171 | if not pcall(ffi.typeof, info.returntype) then 172 | if info.returntype:startswith("struct") then 173 | info.returntype = "struct " .. prepend .. info.returntype:gsub("^struct ", "") 174 | else 175 | info.returntype = prepend .. info.returntype 176 | end 177 | end 178 | 179 | a("%s SteamAPI_%s_%s%s;", info.returntype, info.classname, info.methodname, args) 180 | end 181 | end 182 | end 183 | 184 | for k,v in pairs(interfaces) do 185 | a("%s *%s();", prepend .. k, v) 186 | end 187 | 188 | a("bool SteamAPI_RestartAppIfNecessary(uint32_t);") 189 | a("bool SteamAPI_Init();") 190 | 191 | header = table.concat(header, "\n") 192 | header = header:gsub("_Bool", "bool") 193 | header = header:gsub("&", "*") 194 | 195 | header = header:gsub("struct "..prepend.."CSteamID %b{} "..prepend.."CSteamID", "uint64_t "..prepend.."CSteamID") 196 | 197 | -- post fix (for callbacks since they don't have json info for their parameters) 198 | for i = 1, 500 do 199 | local ok, res = pcall(ffi.real_cdef, header) 200 | if ok then break end 201 | local t, line = res:match("declaration specifier expected near '(.-)' at line (.+)") 202 | line = tonumber(line) 203 | if t and line then 204 | local lines = header:split("\n") 205 | lines[line] = lines[line]:gsub(t, function() return prepend .. t end) 206 | header = table.concat(lines, "\n") 207 | end 208 | end 209 | 210 | local ok, err = ffi.cdef(header) 211 | 212 | if not ok then 213 | local line = tonumber(err:match("line (%d+)")) 214 | if line then 215 | local lines = header:split("\n") 216 | for i = line - 5, line + 5 do 217 | logn(i, ": " .. lines[i], i == line and "<<<<" or "") 218 | end 219 | end 220 | end 221 | 222 | local lua = {} 223 | table.insert(lua, "--this file has been auto generated") 224 | table.insert(lua, "local ffi = require('ffi')") 225 | table.insert(lua, "ffi.cdef[[" .. header .. "]]") 226 | table.insert(lua, [[ 227 | local lib 228 | 229 | if jit.os == "Windows" then 230 | if jit.arch == "x64" then 231 | lib = ffi.load("steam_api64") 232 | elseif jit.arch == "x86" then 233 | lib = ffi.load("steam_api") 234 | end 235 | else 236 | lib = ffi.load("libsteam_api") 237 | end 238 | 239 | local appid 240 | 241 | do 242 | local file = io.open("steam_appid.txt") 243 | 244 | if file then 245 | appid = tonumber(file:read("*all")) 246 | io.close(file) 247 | else 248 | local file, err = io.open("steam_appid.txt", "w") 249 | if file then 250 | file:write("480") 251 | io.close(file) 252 | appid = 480 253 | else 254 | error("failed to write steam_appid.txt! (it's needed) in cd : " .. err) 255 | end 256 | end 257 | end 258 | 259 | if appid == 480 then 260 | print("steamworks.lua: using dummy appid ('Spacewar' the steamworks example)") 261 | print("steamworks.lua: you have to modify ./steam_appid.txt to change it") 262 | end 263 | 264 | local steamworks = {} 265 | 266 | if not lib.SteamAPI_Init() then 267 | error("failed to initialize steamworks") 268 | end 269 | 270 | 271 | steamworks.client_ptr = lib.SteamClient() 272 | if steamworks.client_ptr == nil then error("SteamClient() returns NULL") end 273 | steamworks.pipe_ptr = lib.SteamAPI_ISteamClient_CreateSteamPipe(steamworks.client_ptr) 274 | if steamworks.pipe_ptr == nil then error("SteamAPI_ISteamClient_CreateSteamPipe() returns NULL") end 275 | steamworks.steam_user_ptr = lib.SteamAPI_ISteamClient_ConnectToGlobalUser(steamworks.client_ptr, steamworks.pipe_ptr) 276 | if steamworks.steam_user_ptr == nil then error("SteamAPI_ISteamClient_ConnectToGlobalUser() returns NULL") end 277 | 278 | ]]) 279 | 280 | local steam_id_meta = {} 281 | 282 | -- caps@caps-MS-7798:~/Downloads/sdk$ grep -rn ./ -e "INTERFACE_VERSION \"" 283 | local versions = { 284 | STEAMUSER_INTERFACE_VERSION = "SteamUser019", 285 | STEAMUGC_INTERFACE_VERSION = "STEAMUGC_INTERFACE_VERSION010", 286 | STEAMVIDEO_INTERFACE_VERSION = "STEAMVIDEO_INTERFACE_V002", 287 | STEAMUNIFIEDMESSAGES_INTERFACE_VERSION = "STEAMUNIFIEDMESSAGES_INTERFACE_VERSION001", 288 | STEAMHTMLSURFACE_INTERFACE_VERSION = "STEAMHTMLSURFACE_INTERFACE_VERSION_004", 289 | STEAMGAMESERVER_INTERFACE_VERSION = "SteamGameServer012", 290 | STEAMUTILS_INTERFACE_VERSION = "SteamUtils009", 291 | STEAMGAMECOORDINATOR_INTERFACE_VERSION = "SteamGameCoordinator001", 292 | STEAMCONTROLLER_INTERFACE_VERSION = "SteamController005", 293 | STEAMREMOTESTORAGE_INTERFACE_VERSION = "STEAMREMOTESTORAGE_INTERFACE_VERSION014", 294 | STEAMGAMESERVERSTATS_INTERFACE_VERSION = "SteamGameServerStats001", 295 | STEAMFRIENDS_INTERFACE_VERSION = "SteamFriends015", 296 | STEAMPARENTALSETTINGS_INTERFACE_VERSION = "STEAMPARENTALSETTINGS_INTERFACE_VERSION001", 297 | STEAMMATCHMAKING_INTERFACE_VERSION = "SteamMatchMaking009", 298 | STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION = "SteamMatchMakingServers002", 299 | STEAMAPPLIST_INTERFACE_VERSION = "STEAMAPPLIST_INTERFACE_VERSION001", 300 | STEAMINVENTORY_INTERFACE_VERSION = "STEAMINVENTORY_INTERFACE_V002", 301 | STEAMHTTP_INTERFACE_VERSION = "STEAMHTTP_INTERFACE_VERSION002", 302 | STEAMAPPS_INTERFACE_VERSION = "STEAMAPPS_INTERFACE_VERSION008", 303 | STEAMMUSICREMOTE_INTERFACE_VERSION = "STEAMMUSICREMOTE_INTERFACE_VERSION001", 304 | STEAMMUSIC_INTERFACE_VERSION = "STEAMMUSIC_INTERFACE_VERSION001", 305 | STEAMUSERSTATS_INTERFACE_VERSION = "STEAMUSERSTATS_INTERFACE_VERSION011", 306 | STEAMSCREENSHOTS_INTERFACE_VERSION = "STEAMSCREENSHOTS_INTERFACE_VERSION003", 307 | STEAMNETWORKING_INTERFACE_VERSION = "SteamNetworking005", 308 | STEAMAPPTICKET_INTERFACE_VERSION = "STEAMAPPTICKET_INTERFACE_VERSION001", 309 | } 310 | 311 | for interface in pairs(interfaces) do 312 | local friendly = interface:sub(2):sub(6):lower() 313 | table.insert(lua, "steamworks." .. friendly .. " = {}") 314 | 315 | if interface == "ISteamClient" then 316 | table.insert(lua, "do") 317 | else 318 | 319 | local version = versions[interface:sub(2):upper() .. "_INTERFACE_VERSION"] or "" 320 | 321 | if interface == "ISteamUtils" then 322 | table.insert(lua, "steamworks." .. friendly .. "_ptr = lib.SteamAPI_ISteamClient_Get" .. interface .. "(steamworks.client_ptr, steamworks.pipe_ptr, '"..version.."')") 323 | else 324 | table.insert(lua, "steamworks." .. friendly .. "_ptr = lib.SteamAPI_ISteamClient_Get" .. interface .. "(steamworks.client_ptr, steamworks.steam_user_ptr, steamworks.pipe_ptr, '"..version.."')") 325 | end 326 | 327 | table.insert(lua, "if steamworks." .. friendly .. "_ptr == nil then\n\t print('steamworks.lua: failed to load "..friendly.." " .. version .."')\nelse") 328 | end 329 | for i, info in ipairs(json.methods) do 330 | if info.classname == interface then 331 | local args = "" 332 | if info.params then 333 | for i, arg in ipairs(info.params) do 334 | args = args .. ("%s%s"):format(arg.paramname, i == #info.params and "" or ", ") 335 | end 336 | end 337 | local arg_line = args 338 | local func = "\tfunction steamworks." .. friendly .. "." .. info.methodname .. "(" .. args .. ")" 339 | if #args > 0 then args = ", " .. args end 340 | if info.returntype == "const char *" then 341 | func = func .. "local str = lib.SteamAPI_"..interface.."_" .. info.methodname .. "(steamworks." .. friendly .. "_ptr" .. args .. ") if str ~= nil then return ffi.string(str) end" 342 | else 343 | func = func .. " return lib.SteamAPI_"..interface.."_" .. info.methodname .. "(steamworks." .. friendly .. "_ptr" .. args .. ")" 344 | end 345 | func = func .. " end" 346 | 347 | if info.params and info.params[1].paramtype == prepend .. "CSteamID" then 348 | info.friendly_interface = friendly 349 | info.arg_line = arg_line:match(".-, (.+)") or "" 350 | table.insert(steam_id_meta, info) 351 | end 352 | 353 | table.insert(lua, func) 354 | end 355 | end 356 | table.insert(lua, "end") 357 | end 358 | 359 | table.insert(lua, "local META = {}") 360 | table.insert(lua, "META.__index = META") 361 | 362 | for i, info in ipairs(steam_id_meta) do 363 | 364 | local name = info.methodname 365 | name = name:gsub("User", "") 366 | name = name:gsub("Friend", "") 367 | local arg_line = info.arg_line 368 | if #arg_line > 0 then arg_line = ", " .. arg_line end 369 | local func = "function META:" .. name .. "(" .. info.arg_line .. ") return steamworks." .. info.friendly_interface .. "." .. info.methodname .. "(self.id" .. arg_line .. ") end" 370 | table.insert(lua, func) 371 | end 372 | 373 | table.insert(lua, "META.__tostring = function(self) return ('[%s]%s'):format(self.id, self:GetPersonaName()) end") 374 | table.insert(lua, "function steamworks.GetFriendObjectFromSteamID(id) return setmetatable({id = id}, META) end") 375 | table.insert(lua, "steamworks.steamid_meta = META") 376 | 377 | table.insert(lua, "return steamworks") 378 | lua = table.concat(lua, "\n") 379 | 380 | vfs.Write("os:" .. e.ROOT_FOLDER .. "framework/lua/build/steamworks/steamworks.lua", lua) 381 | runfile("lua/build/steamworks/steamworks.lua") -------------------------------------------------------------------------------- /steamworks/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | -------------------------------------------------------------------------------- /steamworks/readme.md: -------------------------------------------------------------------------------- 1 | #TODO 2 | 3 | This is built from steam_api.json found in the offical steamworks SDK 4 | -------------------------------------------------------------------------------- /vulkan/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . ../generic.sh 4 | --------------------------------------------------------------------------------