mirror of https://github.com/minetest/minetest.git
lua 5.3 compatiblity
This commit is contained in:
parent
696148e298
commit
5d7a1c1020
|
@ -167,10 +167,20 @@ else()
|
||||||
message (STATUS "LuaJIT detection disabled! (ENABLE_LUAJIT=0)")
|
message (STATUS "LuaJIT detection disabled! (ENABLE_LUAJIT=0)")
|
||||||
endif()
|
endif()
|
||||||
if(NOT USE_LUAJIT)
|
if(NOT USE_LUAJIT)
|
||||||
message(STATUS "LuaJIT not found, using bundled Lua.")
|
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
|
||||||
set(LUA_LIBRARY "lua")
|
if(NOT LUA_LIBRARY)
|
||||||
set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src")
|
set(LUA_LIBRARY "lua")
|
||||||
add_subdirectory(lua)
|
endif()
|
||||||
|
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION_NUM[ \t]+[0-9]+.*")
|
||||||
|
STRING(REGEX REPLACE "^#define[ \t]+LUA_VERSION_NUM[ \t]+([0-9]+).*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
|
||||||
|
UNSET(lua_version_str)
|
||||||
|
message(STATUS "Lua specified, using ${LUA_VERSION_STRING} ${LUA_LIBRARY}")
|
||||||
|
else()
|
||||||
|
message(STATUS "LuaJIT not found, using bundled Lua.")
|
||||||
|
set(LUA_LIBRARY "lua")
|
||||||
|
set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src")
|
||||||
|
add_subdirectory(lua)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(GMP REQUIRED)
|
find_package(GMP REQUIRED)
|
||||||
|
|
|
@ -316,7 +316,7 @@ std::vector<aabb3f> read_aabb3f_vector(lua_State *L, int index, f32 scale)
|
||||||
{
|
{
|
||||||
std::vector<aabb3f> boxes;
|
std::vector<aabb3f> boxes;
|
||||||
if(lua_istable(L, index)){
|
if(lua_istable(L, index)){
|
||||||
int n = lua_objlen(L, index);
|
int n = LUA_LENGTH(L, index);
|
||||||
// Check if it's a single box or a list of boxes
|
// Check if it's a single box or a list of boxes
|
||||||
bool possibly_single_box = (n == 6);
|
bool possibly_single_box = (n == 6);
|
||||||
for(int i = 1; i <= n && possibly_single_box; i++){
|
for(int i = 1; i <= n && possibly_single_box; i++){
|
||||||
|
|
|
@ -32,3 +32,19 @@ struct EnumString es_ItemType[] =
|
||||||
{ITEM_TOOL, "tool"},
|
{ITEM_TOOL, "tool"},
|
||||||
{0, NULL},
|
{0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM >= 502
|
||||||
|
LUALIB_API int luaL_pushtype (lua_State *L, int narg) {
|
||||||
|
if (!luaL_callmeta(L, narg, "__type"))
|
||||||
|
lua_pushstring(L, luaL_typename(L, narg));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
|
||||||
|
const char *msg;
|
||||||
|
luaL_pushtype(L, narg);
|
||||||
|
msg = lua_pushfstring(L, "%s expected, got %s",
|
||||||
|
tname, lua_tostring(L, -1));
|
||||||
|
return luaL_argerror(L, narg, msg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -21,9 +21,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#define C_TYPES_H_
|
#define C_TYPES_H_
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "lua.h"
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM >= 502
|
||||||
|
#define luaL_reg luaL_Reg
|
||||||
|
#define LUA_LENGTH(L, I) lua_rawlen((L), (I))
|
||||||
|
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
|
||||||
|
LUALIB_API int (luaL_pushtype) (lua_State *L, int idx);
|
||||||
|
#else
|
||||||
|
#define LUA_LENGTH(L, I) lua_objlen((L), (I))
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
|
|
@ -378,7 +378,12 @@ void LuaAreaStore::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Can be created from Lua (AreaStore())
|
// Can be created from Lua (AreaStore())
|
||||||
|
|
|
@ -676,8 +676,8 @@ int ModApiEnvMod::l_get_perlin(lua_State *L)
|
||||||
if (lua_istable(L, 1)) {
|
if (lua_istable(L, 1)) {
|
||||||
read_noiseparams(L, 1, ¶ms);
|
read_noiseparams(L, 1, ¶ms);
|
||||||
} else {
|
} else {
|
||||||
params.seed = luaL_checkint(L, 1);
|
params.seed = luaL_checkinteger(L, 1);
|
||||||
params.octaves = luaL_checkint(L, 2);
|
params.octaves = luaL_checkinteger(L, 2);
|
||||||
params.persist = luaL_checknumber(L, 3);
|
params.persist = luaL_checknumber(L, 3);
|
||||||
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
||||||
}
|
}
|
||||||
|
@ -849,9 +849,9 @@ int ModApiEnvMod::l_find_path(lua_State *L)
|
||||||
|
|
||||||
v3s16 pos1 = read_v3s16(L, 1);
|
v3s16 pos1 = read_v3s16(L, 1);
|
||||||
v3s16 pos2 = read_v3s16(L, 2);
|
v3s16 pos2 = read_v3s16(L, 2);
|
||||||
unsigned int searchdistance = luaL_checkint(L, 3);
|
unsigned int searchdistance = luaL_checkinteger(L, 3);
|
||||||
unsigned int max_jump = luaL_checkint(L, 4);
|
unsigned int max_jump = luaL_checkinteger(L, 4);
|
||||||
unsigned int max_drop = luaL_checkint(L, 5);
|
unsigned int max_drop = luaL_checkinteger(L, 5);
|
||||||
algorithm algo = A_PLAIN_NP;
|
algorithm algo = A_PLAIN_NP;
|
||||||
if (!lua_isnil(L, 6)) {
|
if (!lua_isnil(L, 6)) {
|
||||||
std::string algorithm = luaL_checkstring(L,6);
|
std::string algorithm = luaL_checkstring(L,6);
|
||||||
|
|
|
@ -455,7 +455,12 @@ void InvRef::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Cannot be created from Lua
|
// Cannot be created from Lua
|
||||||
|
|
|
@ -427,7 +427,12 @@ void LuaItemStack::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Can be created from Lua (LuaItemStack(itemstack or itemstring or table or nil))
|
// Can be created from Lua (LuaItemStack(itemstack or itemstring or table or nil))
|
||||||
|
@ -558,7 +563,7 @@ int ModApiItemMod::l_get_content_id(lua_State *L)
|
||||||
int ModApiItemMod::l_get_name_from_content_id(lua_State *L)
|
int ModApiItemMod::l_get_name_from_content_id(lua_State *L)
|
||||||
{
|
{
|
||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
content_t c = luaL_checkint(L, 1);
|
content_t c = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
||||||
const char *name = ndef->get(c).name.c_str();
|
const char *name = ndef->get(c).name.c_str();
|
||||||
|
|
|
@ -338,7 +338,12 @@ void NodeMetaRef::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Cannot be created from Lua
|
// Cannot be created from Lua
|
||||||
|
|
|
@ -154,7 +154,12 @@ void NodeTimerRef::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Cannot be created from Lua
|
// Cannot be created from Lua
|
||||||
|
|
|
@ -72,8 +72,8 @@ int LuaPerlinNoise::create_object(lua_State *L)
|
||||||
if (lua_istable(L, 1)) {
|
if (lua_istable(L, 1)) {
|
||||||
read_noiseparams(L, 1, ¶ms);
|
read_noiseparams(L, 1, ¶ms);
|
||||||
} else {
|
} else {
|
||||||
params.seed = luaL_checkint(L, 1);
|
params.seed = luaL_checkinteger(L, 1);
|
||||||
params.octaves = luaL_checkint(L, 2);
|
params.octaves = luaL_checkinteger(L, 2);
|
||||||
params.persist = luaL_checknumber(L, 3);
|
params.persist = luaL_checknumber(L, 3);
|
||||||
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
params.spread = v3f(1, 1, 1) * luaL_checknumber(L, 4);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,12 @@ void LuaPerlinNoise::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_openlib(L, 0, methods, 0);
|
#if LUA_VERSION_NUM < 502
|
||||||
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_register(L, className, create_object);
|
lua_register(L, className, create_object);
|
||||||
|
@ -359,7 +364,6 @@ LuaPerlinNoiseMap *LuaPerlinNoiseMap::checkobject(lua_State *L, int narg)
|
||||||
void *ud = luaL_checkudata(L, narg, className);
|
void *ud = luaL_checkudata(L, narg, className);
|
||||||
if (!ud)
|
if (!ud)
|
||||||
luaL_typerror(L, narg, className);
|
luaL_typerror(L, narg, className);
|
||||||
|
|
||||||
return *(LuaPerlinNoiseMap **)ud;
|
return *(LuaPerlinNoiseMap **)ud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +389,12 @@ void LuaPerlinNoiseMap::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_openlib(L, 0, methods, 0);
|
#if LUA_VERSION_NUM < 502
|
||||||
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_register(L, className, create_object);
|
lua_register(L, className, create_object);
|
||||||
|
@ -490,7 +499,12 @@ void LuaPseudoRandom::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_openlib(L, 0, methods, 0);
|
#if LUA_VERSION_NUM < 502
|
||||||
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_register(L, className, create_object);
|
lua_register(L, className, create_object);
|
||||||
|
@ -589,7 +603,12 @@ void LuaPcgRandom::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_openlib(L, 0, methods, 0);
|
#if LUA_VERSION_NUM < 502
|
||||||
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_register(L, className, create_object);
|
lua_register(L, className, create_object);
|
||||||
|
@ -704,7 +723,12 @@ void LuaSecureRandom::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_openlib(L, 0, methods, 0);
|
#if LUA_VERSION_NUM < 502
|
||||||
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_register(L, className, create_object);
|
lua_register(L, className, create_object);
|
||||||
|
|
|
@ -1685,7 +1685,12 @@ void ObjectRef::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Cannot be created from Lua
|
// Cannot be created from Lua
|
||||||
|
|
|
@ -176,7 +176,12 @@ void LuaSettings::Register(lua_State* L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Can be created from Lua (Settings(filename))
|
// Can be created from Lua (Settings(filename))
|
||||||
|
|
|
@ -450,7 +450,12 @@ void LuaVoxelManip::Register(lua_State *L)
|
||||||
|
|
||||||
lua_pop(L, 1); // drop metatable
|
lua_pop(L, 1); // drop metatable
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM < 502
|
||||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||||
|
#else
|
||||||
|
lua_newtable(L);
|
||||||
|
luaL_setfuncs(L, methods, 0);
|
||||||
|
#endif
|
||||||
lua_pop(L, 1); // drop methodtable
|
lua_pop(L, 1); // drop methodtable
|
||||||
|
|
||||||
// Can be created from Lua (VoxelManip())
|
// Can be created from Lua (VoxelManip())
|
||||||
|
|
Loading…
Reference in New Issue