Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for recent odin versions and add lua_newlib function #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rivten
Copy link

@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