Skip to content

support lua5.3 #18

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@
#include <stdlib.h>
#include <string.h>

// For lua5.2 support, instead we could replace all the luaL_register's with whatever
// lua5.2's equivalent function is, but this is easier so whatever.
#define LUA_COMPAT_MODULE
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <enet/enet.h>

#if LUA_VERSION_NUM < 502
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
#endif

#if LUA_VERSION_NUM >= 502
#ifndef luaL_checkint
#define luaL_checkint luaL_checkinteger
#endif
#endif

#define check_host(l, idx)\
*(ENetHost**)luaL_checkudata(l, idx, "enet_host")

Expand Down Expand Up @@ -778,15 +786,13 @@ int luaopen_enet(lua_State *l) {

// create metatables
luaL_newmetatable(l, "enet_host");
lua_newtable(l); // index
luaL_register(l, NULL, enet_host_funcs);
luaL_newlib(l, enet_host_funcs);
lua_setfield(l, -2, "__index");
lua_pushcfunction(l, host_gc);
lua_setfield(l, -2, "__gc");

luaL_newmetatable(l, "enet_peer");
lua_newtable(l);
luaL_register(l, NULL, enet_peer_funcs);
luaL_newlib(l, enet_peer_funcs);
lua_setfield(l, -2, "__index");
lua_pushcfunction(l, peer_tostring);
lua_setfield(l, -2, "__tostring");
Expand All @@ -801,6 +807,6 @@ int luaopen_enet(lua_State *l) {

lua_setfield(l, LUA_REGISTRYINDEX, "enet_peers");

luaL_register(l, "enet", enet_funcs);
luaL_newlib(l, enet_funcs);
return 1;
}
2 changes: 1 addition & 1 deletion examples/channels/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require "enet"
local enet = require "enet"

local host = enet.host_create()
local server = host:connect("localhost:7890", 2)
Expand Down
2 changes: 1 addition & 1 deletion examples/channels/server.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require "enet"
local enet =require "enet"

local channel_responders = {
[0] = function(event)
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require "enet"
local enet = require "enet"

local host = enet.host_create()
local server = host:connect("localhost:5678")
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "enet"
local enet = require "enet"

local host = enet.host_create"localhost:5678"

Expand All @@ -16,4 +16,4 @@ while true do
end

end
end
end
2 changes: 1 addition & 1 deletion examples/unreliable/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require "enet"
local enet = require "enet"

local host = enet.host_create()
local server = host:connect("localhost:6789", 2)
Expand Down
2 changes: 1 addition & 1 deletion examples/unreliable/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "enet"
local enet = require "enet"

local host = enet.host_create("localhost:6789", nil, 2)

Expand Down