<commit_before># Vida

Vida is a Lua module that allows you to include C code and call it
right from your Lua code. 

## REQUIREMENTS

* LuaJit 2.0+

* Clang must be installed and working from the command line

## HOW TO USE

You include the vida module as normal. Call vida.source to provide
C code together with a C interface that will be passed along to
FFI. The return value will be the FFI namespace of the loaded dynamic
library.

Example:

```lua
local vida = require('vida')

local fast = vida.source([[
    // C interface
    int func(int a, int b);
]],
[[
    // C implementation
    int func(int a, int b) {
        return a + b;
    }
]])

print(fast.func(3, 5)) -- should print out 8
```<commit_msg>describe advantages<commit_after># Vida

Vida is a Lua module that allows you to include C code and call it
right from your Lua code. 

## Requirements

* Linux only (for now)
* LuaJit 2.0+
* A working copy of clang or gcc available from the command line

## How to use

You include the vida module as normal. Call `vida.source` to provide
C code together with a C interface that will be passed along to
FFI. The return value will be the FFI namespace of the loaded dynamic
library.

Example:

```lua
local vida = require('vida')

local fast = vida.source([[
    // C interface
    int func(int a, int b);
]],
[[
    // C implementation
    int func(int a, int b) {
        return a + b;
    }
]])

print(fast.func(3, 5)) -- should print out 8
```

## How it works

Each call to `vida.source` builds a new shared library using clang
or gcc called from the command line with appropriate arguments.
The shared library is named using an MD5 hash of the C source code,
opened for immediate use, then saved in a cache directory and reused in
later runs.

## Advantages

There are several reasons to use vida. 

* No complicated build steps needed, everything is in Lua files.
* Performance of simple C functions often 6x faster than LuaJIT
compiled Lua code.
* No new language to learn (compare to Terra).
* No changes to LuaJIT interpreter required.
{'fraction_non_alphanumeric': 0.07681088964511425, 'fraction_numerical': 0.00583373845405931, 'mean_word_length': 3.323529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4240029', 'n_tokens_mistral': 632, 'n_tokens_neox': 608, 'n_words': 319}