diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-07-17 17:13:45 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-07-17 17:13:45 +0200 |
| commit | c83e5d2713334d39bf0718f626cab387f7331a98 (patch) | |
| tree | fc3a55eae0ca2d5e5b5398699150123203c77c65 /c-embed-lua/main.c | |
| parent | 22840a3551d6564ea271d4be6ef7b539d4eba409 (diff) | |
| download | probe-c83e5d2713334d39bf0718f626cab387f7331a98.tar.gz | |
Added exposed C functions to Lua embed
Diffstat (limited to 'c-embed-lua/main.c')
| -rw-r--r-- | c-embed-lua/main.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/c-embed-lua/main.c b/c-embed-lua/main.c index 7ab678a..662ea70 100644 --- a/c-embed-lua/main.c +++ b/c-embed-lua/main.c @@ -4,10 +4,21 @@ #include "hi.h" +static int l_sum(lua_State *L) { + double a = luaL_checknumber(L, 1); + double b = luaL_checknumber(L, 2); + lua_pushnumber(L, a + b); + return 1; +} + int main(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); + // You do not need to prefix name of the function with `c_`. I did it to + // make it clear in the lua script code that this is a custom function. + lua_register(L, "c_sum", l_sum); + // Not wise since this is not a null-terminated string. /* luaL_dostring(L, (const char*)hi); */ |
