Skip to content

Commit

Permalink
add lua5.2 support for no particular reason
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Aug 22, 2014
1 parent f878233 commit 925ff1d
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 46 deletions.
12 changes: 8 additions & 4 deletions SConscript
Expand Up @@ -248,13 +248,17 @@ def findLibs(env, conf):

if not GetOption('nolua') and not GetOption('renderer'):
#Look for Lua
luaver = "lua5.1"
if not conf.CheckLib(['lua5.1', 'lua-5.1', 'lua51', 'lua']):
if platform != "Darwin" or not conf.CheckFramework("Lua"):
if conf.CheckLib(['lua5.2', 'lua-5.2', 'lua52']):
env.Append(CPPDEFINES=["LUA_COMPAT_ALL"])
luaver = "lua5.2"
elif platform != "Darwin" or not conf.CheckFramework("Lua"):
FatalError("lua5.1 development library not found or not installed")
if platform == "Linux":
try:
env.ParseConfig('pkg-config --cflags lua5.1')
env.ParseConfig('pkg-config --libs lua5.1')
env.ParseConfig("pkg-config --cflags {0}".format(luaver))
env.ParseConfig("pkg-config --libs {0}".format(luaver))
except:
pass

Expand Down Expand Up @@ -479,7 +483,7 @@ if GetOption('beta'):
#Generate list of sources to compile
sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/*/*/*.cpp") + Glob("generated/*.cpp")
if not GetOption('nolua') and not GetOption('renderer'):
sources += Glob("src/lua/socket/*.c")
sources += Glob("src/lua/socket/*.c") + Glob("src/lua/LuaCompat.c")

if platform == "Windows" and not msvc:
sources += env.RES('resources/powder-res.rc')
Expand Down
10 changes: 5 additions & 5 deletions src/lua/LuaBit.cpp
Expand Up @@ -29,7 +29,7 @@

#define LUA_BITOP_VERSION "1.0.2"

#include "luainc.h"
#include "LuaCompat.h"

#ifdef _MSC_VER
/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
Expand Down Expand Up @@ -178,11 +178,11 @@ int luaopen_bit(lua_State *L)
msg = "arithmetic right-shift broken";
luaL_error(L, "bit library self-test failed (%s)", msg);
}
#if LUA_VERSION_NUM < 502
//#if LUA_VERSION_NUM < 502
luaL_register(L, "bit", bit_funcs);
#else
luaL_newlib(L, bit_funcs);
#endif
//#else
// luaL_newlib(L, bit_funcs);
//#endif
return 1;
}
#endif
11 changes: 11 additions & 0 deletions src/lua/LuaCompat.c
@@ -0,0 +1,11 @@
#include "LuaCompat.h"

#if LUA_VERSION_NUM >= 502
//implement missing luaL_typerror function
int luaL_typerror (lua_State *L, int narg, const char *tname)
{
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
}

#endif
7 changes: 7 additions & 0 deletions src/lua/luainc.h → src/lua/LuaCompat.h
Expand Up @@ -16,6 +16,13 @@ extern "C"
#include "lualib.h"
#endif

#if LUA_VERSION_NUM >= 502
#define luaL_getn(L,i) lua_rawlen(L, (i))
#define LUA_GLOBALSINDEX LUA_RIDX_GLOBALS

LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/lua/LuaLuna.h
@@ -1,7 +1,7 @@
#pragma once
//http://lua-users.org/wiki/SimplerCppBinding

#include "luainc.h"
#include "LuaCompat.h"

template <typename T> class Luna
{
Expand Down
14 changes: 7 additions & 7 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -139,7 +139,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
int i = 0, j;
char tmpname[12];
int currentElementMeta, currentElement;
const static struct luaL_reg tptluaapi [] = {
const static struct luaL_Reg tptluaapi [] = {
{"test", &luatpt_test},
{"drawtext", &luatpt_drawtext},
{"create", &luatpt_create},
Expand Down Expand Up @@ -442,7 +442,7 @@ int LuaScriptInterface::tpt_newIndex(lua_State *l)

void LuaScriptInterface::initInterfaceAPI()
{
struct luaL_reg interfaceAPIMethods [] = {
struct luaL_Reg interfaceAPIMethods [] = {
{"showWindow", interface_showWindow},
{"closeWindow", interface_closeWindow},
{"addComponent", interface_addComponent},
Expand Down Expand Up @@ -535,7 +535,7 @@ int LuaScriptInterface::particlePropertiesCount;
void LuaScriptInterface::initSimulationAPI()
{
//Methods
struct luaL_reg simulationAPIMethods [] = {
struct luaL_Reg simulationAPIMethods [] = {
{"partNeighbours", simulation_partNeighbours},
{"partNeighbors", simulation_partNeighbours},
{"partChangeType", simulation_partChangeType},
Expand Down Expand Up @@ -1765,7 +1765,7 @@ int LuaScriptInterface::simulation_neighbours(lua_State * l)
void LuaScriptInterface::initRendererAPI()
{
//Methods
struct luaL_reg rendererAPIMethods [] = {
struct luaL_Reg rendererAPIMethods [] = {
{"renderModes", renderer_renderModes},
{"displayModes", renderer_displayModes},
{"colourMode", renderer_colourMode},
Expand Down Expand Up @@ -1957,7 +1957,7 @@ int LuaScriptInterface::renderer_debugHUD(lua_State * l)
void LuaScriptInterface::initElementsAPI()
{
//Methods
struct luaL_reg elementsAPIMethods [] = {
struct luaL_Reg elementsAPIMethods [] = {
{"allocate", elements_allocate},
{"element", elements_element},
{"property", elements_property},
Expand Down Expand Up @@ -2474,7 +2474,7 @@ int LuaScriptInterface::elements_free(lua_State * l)
void LuaScriptInterface::initGraphicsAPI()
{
//Methods
struct luaL_reg graphicsAPIMethods [] = {
struct luaL_Reg graphicsAPIMethods [] = {
{"textSize", graphics_textSize},
{"drawText", graphics_drawText},
{"drawLine", graphics_drawLine},
Expand Down Expand Up @@ -2683,7 +2683,7 @@ int LuaScriptInterface::graphics_getHexColor(lua_State * l)
void LuaScriptInterface::initFileSystemAPI()
{
//Methods
struct luaL_reg fileSystemAPIMethods [] = {
struct luaL_Reg fileSystemAPIMethods [] = {
{"list", fileSystem_list},
{"exists", fileSystem_exists},
{"isFile", fileSystem_isFile},
Expand Down
2 changes: 1 addition & 1 deletion src/lua/LuaScriptInterface.h
@@ -1,7 +1,7 @@
#ifndef LUASCRIPTINTERFACE_H_
#define LUASCRIPTINTERFACE_H_

#include "luainc.h"
#include "LuaCompat.h"

#include "CommandInterface.h"
#include "simulation/Simulation.h"
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/auxiliar.c
Expand Up @@ -24,7 +24,7 @@ int auxiliar_open(lua_State *L) {
* Creates a new class with given methods
* Methods whose names start with __ are passed directly to the metatable.
\*-------------------------------------------------------------------------*/
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func) {
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
luaL_newmetatable(L, classname); /* mt */
/* create __index table to place methods */
lua_pushstring(L, "__index"); /* mt,"__index" */
Expand Down
4 changes: 2 additions & 2 deletions src/lua/socket/auxiliar.h
Expand Up @@ -31,10 +31,10 @@
* RCS ID: $Id: auxiliar.h,v 1.9 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/

#include "../luainc.h"
#include "../LuaCompat.h"

int auxiliar_open(lua_State *L);
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func);
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);
void auxiliar_add2group(lua_State *L, const char *classname, const char *group);
void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/buffer.c
Expand Up @@ -222,7 +222,7 @@ static int recvline(p_buffer buf, luaL_Buffer *b) {
pos = 0;
while (pos < count && data[pos] != '\n') {
/* we ignore all \r's */
if (data[pos] != '\r') luaL_putchar(b, data[pos]);
if (data[pos] != '\r') luaL_addchar(b, data[pos]);
pos++;
}
if (pos < count) { /* found '\n' */
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/buffer.h
Expand Up @@ -17,7 +17,7 @@
*
* RCS ID: $Id: buffer.h,v 1.12 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"

#include "io.h"
#include "timeout.h"
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/except.c
Expand Up @@ -18,7 +18,7 @@ static int finalize(lua_State *L);
static int do_nothing(lua_State *L);

/* except functions */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{"newtry", global_newtry},
{"protect", global_protect},
{NULL, NULL}
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/except.h
Expand Up @@ -28,7 +28,7 @@
* RCS ID: $Id: except.h,v 1.2 2005/09/29 06:11:41 diego Exp $
\*=========================================================================*/

#include "../luainc.h"
#include "../LuaCompat.h"

int except_open(lua_State *L);

Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/inet.c
Expand Up @@ -18,7 +18,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp);
static int inet_global_gethostname(lua_State *L);

/* DNS functions */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{ "toip", inet_global_toip },
{ "tohostname", inet_global_tohostname },
{ "gethostname", inet_global_gethostname},
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/inet.h
Expand Up @@ -16,7 +16,7 @@
*
* RCS ID: $Id: inet.h,v 1.16 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"
#include "socket.h"
#include "timeout.h"

Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/io.h
Expand Up @@ -15,7 +15,7 @@
* RCS ID: $Id: io.h,v 1.11 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include <stdio.h>
#include "../luainc.h"
#include "../LuaCompat.h"

#include "timeout.h"

Expand Down
4 changes: 2 additions & 2 deletions src/lua/socket/luasocket.c
Expand Up @@ -37,7 +37,7 @@ static int base_open(lua_State *L);
/*-------------------------------------------------------------------------*\
* Modules and functions
\*-------------------------------------------------------------------------*/
static const luaL_reg mod[] = {
static const luaL_Reg mod[] = {
{"auxiliar", auxiliar_open},
{"except", except_open},
{"timeout", timeout_open},
Expand All @@ -49,7 +49,7 @@ static const luaL_reg mod[] = {
{NULL, NULL}
};

static luaL_reg func[] = {
static luaL_Reg func[] = {
{"skip", global_skip},
{"__unload", global_unload},
{NULL, NULL}
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/luasocket.h
Expand Up @@ -8,7 +8,7 @@
*
* RCS ID: $Id: luasocket.h,v 1.25 2007/06/11 23:44:54 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"

/*-------------------------------------------------------------------------*\
* Current socket library version
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/options.h
Expand Up @@ -10,7 +10,7 @@
* RCS ID: $Id: options.h,v 1.4 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/

#include "../luainc.h"
#include "../LuaCompat.h"
#include "socket.h"

/* option registry */
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/select.c
Expand Up @@ -24,7 +24,7 @@ static void make_assoc(lua_State *L, int tab);
static int global_select(lua_State *L);

/* functions in library namespace */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{"select", global_select},
{NULL, NULL}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/socket.lua.cpp
@@ -1,6 +1,6 @@
#ifdef LUACONSOLE
// socket.lua from luasocket compiled into a cpp file
#include "../luainc.h"
#include "../LuaCompat.h"
void luaopen_socket(lua_State *l){
int socket_luac_sz=4061;
const char* socket_luac="-----------------------------------------------------------------------------\012-- LuaSocket helper module\012-- Author: Diego Nehab\012-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $\012-----------------------------------------------------------------------------\012\012-----------------------------------------------------------------------------\012-- Declare module and import dependencies\012-----------------------------------------------------------------------------\012local base = _G\012local string = require(\042string\042)\012local math = require(\042math\042)\012local socket = require(\042socket.core\042)\012module(\042socket\042)\012\012-----------------------------------------------------------------------------\012-- Exported auxiliar functions\012-----------------------------------------------------------------------------\012function connect(address, port, laddress, lport)\012 local sock, err = socket.tcp()\012 if not sock then return nil, err end\012 if laddress then\012 local res, err = sock:bind(laddress, lport, -1)\012 if not res then return nil, err end\012 end\012 local res, err = sock:connect(address, port)\012 if not res then return nil, err end\012 return sock\012end\012\012function bind(host, port, backlog)\012 local sock, err = socket.tcp()\012 if not sock then return nil, err end\012 sock:setoption(\042reuseaddr\042, true)\012 local res, err = sock:bind(host, port)\012 if not res then return nil, err end\012 res, err = sock:listen(backlog)\012 if not res then return nil, err end\012 return sock\012end\012\012try = newtry()\012\012function choose(table)\012 return function(name, opt1, opt2)\012 if base.type(name) ~= \042string\042 then\012 name, opt1, opt2 = \042default\042, name, opt1\012 end\012 local f = table[name or \042nil\042]\012 if not f then base.error(\042unknown key (\042.. base.tostring(name) ..\042)\042, 3)\012 else return f(opt1, opt2) end\012 end\012end\012\012-----------------------------------------------------------------------------\012-- Socket sources and sinks, conforming to LTN12\012-----------------------------------------------------------------------------\012-- create namespaces inside LuaSocket namespace\012sourcet = {}\012sinkt = {}\012\012BLOCKSIZE = 2048\012\012sinkt[\042close-when-done\042] = function(sock)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function(self, chunk, err)\012 if not chunk then\012 sock:close()\012 return 1\012 else return sock:send(chunk) end\012 end\012 })\012end\012\012sinkt[\042keep-open\042] = function(sock)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function(self, chunk, err)\012 if chunk then return sock:send(chunk)\012 else return 1 end\012 end\012 })\012end\012\012sinkt[\042default\042] = sinkt[\042keep-open\042]\012\012sink = choose(sinkt)\012\012sourcet[\042by-length\042] = function(sock, length)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function()\012 if length <= 0 then return nil end\012 local size = math.min(socket.BLOCKSIZE, length)\012 local chunk, err = sock:receive(size)\012 if err then return nil, err end\012 length = length - string.len(chunk)\012 return chunk\012 end\012 })\012end\012\012sourcet[\042until-closed\042] = function(sock)\012 local done\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function()\012 if done then return nil end\012 local chunk, err, partial = sock:receive(socket.BLOCKSIZE)\012 if not err then return chunk\012 elseif err == \042closed\042 then\012 sock:close()\012 done = 1\012 return partial\012 else return nil, err end\012 end\012 })\012end\012\012\012sourcet[\042default\042] = sourcet[\042until-closed\042]\012\012source = choose(sourcet)\012\012";
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/socket.lua.h
@@ -1,2 +1,2 @@
#include "../luainc.h"
#include "../LuaCompat.h"
void luaopen_socket(lua_State *l);
4 changes: 2 additions & 2 deletions src/lua/socket/tcp.c
Expand Up @@ -35,7 +35,7 @@ static int meth_setfd(lua_State *L);
static int meth_dirty(lua_State *L);

/* tcp object methods */
static luaL_reg tcp[] = {
static luaL_Reg tcp[] = {
{"__gc", meth_close},
{"__tostring", auxiliar_tostring},
{"accept", meth_accept},
Expand Down Expand Up @@ -70,7 +70,7 @@ static t_opt opt[] = {
};

/* functions in library namespace */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{"tcp", global_create},
{NULL, NULL}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/tcp.h
Expand Up @@ -16,7 +16,7 @@
*
* RCS ID: $Id: tcp.h,v 1.7 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"

#include "buffer.h"
#include "timeout.h"
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/timeout.c
Expand Up @@ -30,7 +30,7 @@
static int timeout_lua_gettime(lua_State *L);
static int timeout_lua_sleep(lua_State *L);

static luaL_reg func[] = {
static luaL_Reg func[] = {
{ "gettime", timeout_lua_gettime },
{ "sleep", timeout_lua_sleep },
{ NULL, NULL }
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/timeout.h
Expand Up @@ -6,7 +6,7 @@
*
* RCS ID: $Id: timeout.h,v 1.14 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"

/* timeout control structure */
typedef struct t_timeout_ {
Expand Down
4 changes: 2 additions & 2 deletions src/lua/socket/udp.c
Expand Up @@ -40,7 +40,7 @@ static int meth_setfd(lua_State *L);
static int meth_dirty(lua_State *L);

/* udp object methods */
static luaL_reg udp[] = {
static luaL_Reg udp[] = {
{"__gc", meth_close},
{"__tostring", auxiliar_tostring},
{"close", meth_close},
Expand Down Expand Up @@ -73,7 +73,7 @@ static t_opt opt[] = {
};

/* functions in library namespace */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{"udp", global_create},
{NULL, NULL}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lua/socket/udp.h
Expand Up @@ -14,7 +14,7 @@
*
* RCS ID: $Id: udp.h,v 1.10 2005/10/07 04:40:59 diego Exp $
\*=========================================================================*/
#include "../luainc.h"
#include "../LuaCompat.h"

#include "timeout.h"
#include "socket.h"
Expand Down
4 changes: 2 additions & 2 deletions src/lua/socket/unix.c
Expand Up @@ -37,7 +37,7 @@ static const char *unix_tryconnect(p_unix un, const char *path);
static const char *unix_trybind(p_unix un, const char *path);

/* unix object methods */
static luaL_reg un[] = {
static luaL_Reg un[] = {
{"__gc", meth_close},
{"__tostring", auxiliar_tostring},
{"accept", meth_accept},
Expand Down Expand Up @@ -69,7 +69,7 @@ static t_opt opt[] = {
};

/* our socket creation function */
static luaL_reg func[] = {
static luaL_Reg func[] = {
{"unix", global_create},
{NULL, NULL}
};
Expand Down

0 comments on commit 925ff1d

Please sign in to comment.