Skip to content

fix for recent odin versions and add lua_newlib function#2

Open
rivten wants to merge 2 commits intoSrMordred:masterfrom
rivten:update-to-recent-odin-and-add-newlib
Open

fix for recent odin versions and add lua_newlib function#2
rivten wants to merge 2 commits intoSrMordred:masterfrom
rivten:update-to-recent-odin-and-add-newlib

Conversation

@rivten
Copy link
Copy Markdown

@rivten rivten commented Nov 2, 2022

I did not test the change on Mac and Windows.

However, with the change, now you can build a SO file that can be loaded from the Lua interpreter standalone

package main

import "core:fmt"
import lua "odin-lua"

swap :: proc "c" (L: ^lua.lua_State) -> i32 {
    arg1 := lua.luaL_checknumber(L, 1)
    arg2 := lua.luaL_checknumber(L, 2)

    lua.lua_pushnumber(L, arg2)
    lua.lua_pushnumber(L, arg1)
    
    return 2
}

@(export)
luaopen_t :: proc "c" (L: ^lua.lua_State) -> i32 {
    lua.luaL_newlib(L, []lua.luaL_Reg {
        {"swap", swap},
        {nil, nil},
    })
    return 1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant