Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ API coverage:
| `lua_load` | Not supported |
| `lua_newstate` | `require('lualua').newstate()` |
| `lua_newtable` | `s:newtable()` |
| `lua_newthread` | Not supported |
| `lua_newthread` | `th = s:newthread()` |
| `lua_newuserdata` | `t = s:newuserdata()` |
| `lua_next` | `b = s:next(index)` |
| `lua_objlen` | `n = s:objlen(index)` |
Expand Down
8 changes: 8 additions & 0 deletions lualua.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ static int lualua_newtable(lua_State *L) {
return 0;
}

static int lualua_newthread(lua_State *L) {
lualua_State *S = lualua_checkstate(L, 1);
lualua_checkoverflow(S, 1);
lua_newthread(S->state);
return 1;
}

static int lualua_newuserdata(lua_State *L) {
lualua_State *S = lualua_checkstate(L, 1);
lualua_checkoverflow(S, 1);
Expand Down Expand Up @@ -706,6 +713,7 @@ static const struct luaL_Reg lualua_state_index[] = {
{"lessthan", lualua_lessthan},
{"loadstring", lualua_loadstring},
{"newtable", lualua_newtable},
{"newthread", lualua_newthread},
{"newuserdata", lualua_newuserdata},
{"next", lualua_next},
{"objlen", lualua_objlen},
Expand Down
15 changes: 15 additions & 0 deletions spec/lualua_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,21 @@ describe('lualua', function()
end)
end)

describe('newthread', function()
it('works', function()
local s = lib.newstate()
nr(1, s:newthread())
assert(true, s:isthread(1))
end)
it('fails on full stack', function()
local s = lib.newstate()
for _ = 1, lib.MINSTACK do
nr(1, s:newthread())
end
assertFails('stack overflow', s.newthread, s)
end)
end)

describe('newuserdata', function()
it('works', function()
local s = lib.newstate()
Expand Down