forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Features(Lualib/Lua(Jit)): Lua Version and Static Linking Support (#209)
- Loading branch information
Showing
68 changed files
with
468 additions
and
20,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
set(LUA_VERSION "lua52" CACHE STRING "Lua version to use") | ||
set_property(CACHE LUA_VERSION PROPERTY STRINGS luajit lua51 lua52 lua53 lua54) | ||
MESSAGE(STATUS "Lua version: ${LUA_VERSION}") | ||
|
||
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") | ||
cmake_policy(SET CMP0135 NEW) | ||
endif() | ||
|
||
option(LUA_STATIC "link lua statically" OFF) | ||
if (LUA_STATIC) | ||
MESSAGE(STATUS "Lua linking: static") | ||
else() | ||
MESSAGE(STATUS "Lua linking: dynamic") | ||
endif() | ||
|
||
if (LUA_VERSION MATCHES "luajit") | ||
add_subdirectory(src/lualib/luajit) | ||
set(LUAJIT_VERSION true) | ||
else() | ||
add_subdirectory(src/lualib/lua) | ||
set(LUAJIT_VERSION false) | ||
endif() | ||
|
||
set_target_properties(lualib PROPERTIES INTERFACE_COMPILE_DEFINITIONS LUAJIT_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> | ||
* This program is free software licensed under GPL version 3 | ||
* Please see the included DOCS/LICENSE.md for more information | ||
*/ | ||
|
||
#include "ElunaCompat.h" | ||
|
||
#if LUA_VERSION_NUM == 501 | ||
const char* luaL_tolstring(lua_State* L, int idx, size_t* len) { | ||
if (!luaL_callmeta(L, idx, "__tostring")) { | ||
int t = lua_type(L, idx), tt = 0; | ||
char const* name = NULL; | ||
switch (t) { | ||
case LUA_TNIL: | ||
lua_pushliteral(L, "nil"); | ||
break; | ||
case LUA_TSTRING: | ||
case LUA_TNUMBER: | ||
lua_pushvalue(L, idx); | ||
break; | ||
case LUA_TBOOLEAN: | ||
if (lua_toboolean(L, idx)) | ||
lua_pushliteral(L, "true"); | ||
else | ||
lua_pushliteral(L, "false"); | ||
break; | ||
default: | ||
tt = luaL_getmetafield(L, idx, "__name"); | ||
name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t); | ||
lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx)); | ||
if (tt != LUA_TNIL) | ||
lua_replace(L, -2); | ||
break; | ||
} | ||
} | ||
else { | ||
if (!lua_isstring(L, -1)) | ||
luaL_error(L, "'__tostring' must return a string"); | ||
} | ||
return lua_tolstring(L, -1, len); | ||
} | ||
|
||
int luaL_getsubtable(lua_State* L, int i, const char* name) { | ||
int abs_i = lua_absindex(L, i); | ||
luaL_checkstack(L, 3, "not enough stack slots"); | ||
lua_pushstring(L, name); | ||
lua_gettable(L, abs_i); | ||
if (lua_istable(L, -1)) | ||
return 1; | ||
lua_pop(L, 1); | ||
lua_newtable(L); | ||
lua_pushstring(L, name); | ||
lua_pushvalue(L, -2); | ||
lua_settable(L, abs_i); | ||
return 0; | ||
} | ||
|
||
int lua_absindex(lua_State* L, int i) { | ||
if (i < 0 && i > LUA_REGISTRYINDEX) | ||
i += lua_gettop(L) + 1; | ||
return i; | ||
} | ||
|
||
#if !defined LUAJIT_VERSION | ||
void* luaL_testudata(lua_State* L, int index, const char* tname) { | ||
void* ud = lua_touserdata(L, index); | ||
if (ud) | ||
{ | ||
if (lua_getmetatable(L, index)) | ||
{ | ||
luaL_getmetatable(L, tname); | ||
if (!lua_rawequal(L, -1, -2)) | ||
ud = NULL; | ||
lua_pop(L, 2); | ||
return ud; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
void luaL_setmetatable(lua_State* L, const char* tname) { | ||
lua_pushstring(L, tname); | ||
lua_rawget(L, LUA_REGISTRYINDEX); | ||
lua_setmetatable(L, -2); | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> | ||
* This program is free software licensed under GPL version 3 | ||
* Please see the included DOCS/LICENSE.md for more information | ||
*/ | ||
|
||
#ifndef ELUNACOMPAT_H | ||
#define ELUNACOMPAT_H | ||
|
||
extern "C" | ||
{ | ||
#include "lua.h" | ||
#include "lauxlib.h" | ||
}; | ||
|
||
/* Compatibility layer for compiling with Lua 5.1 or LuaJIT */ | ||
#if LUA_VERSION_NUM == 501 | ||
int luaL_getsubtable(lua_State* L, int i, const char* name); | ||
const char* luaL_tolstring(lua_State* L, int idx, size_t* len); | ||
int lua_absindex(lua_State* L, int i); | ||
#define lua_pushglobaltable(L) \ | ||
lua_pushvalue((L), LUA_GLOBALSINDEX) | ||
#define lua_rawlen(L, idx) \ | ||
lua_objlen(L, idx) | ||
#define lua_pushunsigned(L, u) \ | ||
lua_pushinteger(L, u) | ||
#define lua_load(L, buf_read, dec_buf, str, NULL) \ | ||
lua_load(L, buf_read, dec_buf, str) | ||
|
||
#if !defined LUAJIT_VERSION | ||
void* luaL_testudata(lua_State* L, int index, const char* tname); | ||
void luaL_setmetatable(lua_State* L, const char* tname); | ||
#define luaL_setfuncs(L, l, n) luaL_register(L, NULL, l) | ||
#endif | ||
#endif | ||
|
||
#if LUA_VERSION_NUM > 502 | ||
#define lua_dump(L, writer, data) \ | ||
lua_dump(L, writer, data, 0) | ||
#define lua_pushunsigned(L, u) \ | ||
lua_pushinteger(L, u) | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.