<commit_before>local ffi = require("ffi")
ffi.cdef[[

typedef struct GLFWwindow GLFWwindow;
typedef struct GLFWmonitor GLFWmonitor;

void glfwMakeContextCurrent (GLFWwindow *window);
GLFWwindow * glfwCreateWindow (int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share);
]]

local window = ffi.C.glfwCreateWindow(100,100,'test',nil,nil)
ffi.C.glfwMakeContextCurrent(window)

while (true) do
end<commit_msg>Update ffi test<commit_after>local ffi = require("ffi")
ffi.cdef[[

typedef struct GLFWwindow GLFWwindow;
typedef struct GLFWmonitor GLFWmonitor;

void glfwMakeContextCurrent (GLFWwindow *window);
GLFWwindow * glfwCreateWindow (int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share);

typedef struct { double x, y; } point_t;
]]

local window = ffi.C.glfwCreateWindow(100,100,'test',nil,nil)
ffi.C.glfwMakeContextCurrent(window)

local buf = ffi.new('unsigned long[?]',10)
buf[1] = 100
print(buf[10],tonumber(buf[1]))

local point
local mt = {
    __add = function(a, b) return point(a.x+b.x, a.y+b.y) end,
    __len = function(a) return math.sqrt(a.x*a.x + a.y*a.y) end,
    __index = {
        area = function(a) return a.x*a.x + a.y*a.y end,
    },
    __gc = {
        print 'GC'
    }
}


point = ffi.metatype("point_t", mt)

local a = point(3, 4)
print(a.x, a.y)  --> 3  4
print(#a)        --> 5
print(a:area())  --> 25
ffi.gc(a,function() print('GC a') end)

print(ffi.sizeof("point_t"))
print(ffi.sizeof(point))

local b = a + point(0.5, 8)
print(#b)        --> 12.5
ffi.gc(b,function() print('GC b') end)

local tt = ffi.new('point_t')
tt.x = 4
tt.y = 4
print(tt:area())
ffi.gc(tt,function() print('GC tt') end)
{'fraction_non_alphanumeric': 0.16240333135038668, 'fraction_numerical': 0.021415823914336704, 'mean_word_length': 4.425806451612903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3546009', 'n_tokens_mistral': 689, 'n_tokens_neox': 652, 'n_words': 155}