Overview
Comment: | unbreak build (oops sorry about that) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
b4009ca1bd19bcf34e0e7553cfa1ac47 |
User & Date: | lexi on 2024-05-07 19:25:37 |
Other Links: | manifest | tags |
Context
2024-07-17
| ||
20:10 | add missing subtitle support check-in: 362f9a6647 user: lexi tags: trunk | |
2024-05-07
| ||
19:25 | unbreak build (oops sorry about that) check-in: b4009ca1bd user: lexi tags: trunk | |
2024-03-15
| ||
18:02 | fix incorrect plural check-in: 3f5d6b4b81 user: lexi tags: trunk | |
Changes
Added bind/bind.h version [9c4f9e0a4b].
1 +#pragma once 2 + 3 +#include <lua.h> 4 +#include <lauxlib.h> 5 + 6 +#include <stddef.h> 7 +#include <stdbool.h> 8 +#include <stdint.h> 9 + 10 +#define _luafn(name) static int LX_##name (lua_State* l) 11 +#define _export(name) lua_pushcfunction(l, LX_##name), lua_setfield(l, -2, #name); 12 + 13 +#define _luaret_bool(b) {lua_pushboolean(l, b); return 1;} 14 +#define _luaAPI(mod, ...) int luaopen_bind_##mod (lua_State* l) { \ 15 + lua_newtable(l); \ 16 + __VA_ARGS__; \ 17 + return 1; \ 18 +} 19 + 20 +/* this comment serves only to unfuck a GCC bug */
Added bind/net.c version [c79d47efa1].
1 +#include "bind.h" 2 + 3 +#include <curl/curl.h> 4 + 5 +#define _str(...) #__VA_ARGS__ 6 +#define _e_tag "(native-bind " __FILE__ ":" _str(__LINE__) ") " 7 + 8 +static size_t 9 +buffer_string 10 +( char* ptr, 11 + size_t size, 12 + size_t nmemb, 13 + void* dest 14 +) { 15 + luaL_Buffer* const data = dest; 16 + luaL_addlstring(data, ptr, size*nmemb); 17 + return size*nmemb; 18 +} 19 + 20 +_luafn(fetchURI) { 21 + const char* p_uri = luaL_checkstring(l,1); 22 + 23 + CURL* h = curl_easy_init(); 24 + if (!h) { 25 + lua_pushstring(l, _e_tag "libcurl failed to init"); 26 + lua_error(l); 27 + } 28 + 29 +// int unwind = lua_gettop(l); 30 + luaL_Buffer download; 31 + luaL_buffinit(l, &download); 32 + 33 + char ebuf [CURL_ERROR_SIZE]; 34 + curl_easy_setopt(h, CURLOPT_URL, p_uri); 35 + curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, buffer_string); 36 + curl_easy_setopt(h, CURLOPT_WRITEDATA, &download); 37 + curl_easy_setopt(h, CURLOPT_FOLLOWLOCATION,true); 38 + curl_easy_setopt(h, CURLOPT_ERRORBUFFER, ebuf); 39 + 40 + CURLcode e = curl_easy_perform(h); 41 + if (e == 0) { 42 + curl_easy_cleanup(h); 43 + luaL_pushresult(&download); 44 + return 1; 45 + } else { 46 +// lua_settop(l,unwind); 47 + lua_pushnil(l); 48 + lua_pushstring(l, ebuf); 49 + return 2; 50 + } 51 +} 52 + 53 +_luaAPI(net, 54 + _export(fetchURI));
Added bind/posix.c version [68a13b3104].
1 +#include "bind.h" 2 + 3 +#include <unistd.h> 4 +#include <stdio.h> 5 +#include <assert.h> 6 + 7 +_luafn(getcwd) { /* getcwd() */ 8 + size_t bufsz = 256; 9 + /* VLA resize hack */ for (;;) { 10 + char cwd [bufsz]; 11 + if (getcwd(cwd, bufsz) == NULL) { 12 + assert(bufsz < (2 * 1024*1024)); /* sanity check */ 13 + bufsz = bufsz * 2; 14 + continue; 15 + } 16 + lua_pushstring(l, cwd); 17 + return 1; 18 + } 19 +} 20 + 21 +_luafn(isatty) { /* isatty(stream) */ 22 + luaL_Stream* stream = lua_touserdata(l, 1); 23 + if (stream == NULL) return 0; 24 + int fd = fileno(stream -> f); 25 + _luaret_bool(isatty(fd)); 26 +} 27 + 28 +_luaAPI(posix, 29 + _export(getcwd); 30 + _export(isatty));
Added bind/strutils.c version [9bbacd41f1].
1 +#include "bind.h" 2 + 3 +_luafn(rangematch) { 4 + luaL_checkstring(l, 1); 5 + luaL_checknumber(l, 2); 6 + luaL_checkstring(l, 3); 7 + 8 + size_t strl = 0, matl = 0, start = lua_tointeger(l, 2)-1; 9 + const char* str = lua_tolstring(l, 1, &strl); 10 + const char* mat = lua_tolstring(l, 3, &matl); 11 + size_t to; 12 + if (start > strl || (to = start + matl) > strl) { 13 + _luaret_bool(false); 14 + } 15 + for (size_t i = start; i<to; ++i) { 16 + if (str[i] != mat[i - start]) _luaret_bool(false); 17 + } 18 + _luaret_bool(true); 19 +} 20 + 21 +_luaAPI(strutils, _export(rangematch));
Added shell.nix version [0124789a13].
1 +{pkgs ? import <nixpkgs> {}, ...}: 2 + 3 +let debuggable = d: d.overrideAttrs(o: rec { 4 + dontStrip = true; 5 +}); 6 + 7 +in pkgs.mkShell { 8 + buildInputs = with pkgs; [ 9 + lua5_4 10 + curl 11 + ]; 12 + shellHook = '' 13 + exec fish 14 + ''; 15 + NIX_ENFORCE_PURITY = false; 16 +}