all repos

olexsmir.xyz @ d0d11629630c0933aa34973a2bfea4ac939ad460

my site, yes, i like lua

olexsmir.xyz/lua/liblego.lua(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local ffi = require "ffi"

ffi.cdef [[
  void free_cstring(char* s);
  char* md_to_html(const char* input);
  char* chroma_css(const char* theme);
]]

local lib = ffi.load "./go/liblego.so"

local M = {}

---@param markdown string
---@return string
function M.md_to_html(markdown)
  local result = lib.md_to_html(markdown)
  local html = ffi.string(result)
  lib.free_cstring(result)
  if html == "" then
    error "failed, good luck"
  end
  return html
end

---@param theme string
---@return string
function M.get_css(theme)
  local result = lib.chroma_css(theme)
  local css = ffi.string(result)
  if css == "" then
    error "failed, good luck"
  end

  css = css:gsub("/%*.-%*/ ", "")
  css = css:gsub("\n$", "")
  return css
end

return M