diff --git a/sol/compatibility.hpp b/sol/compatibility.hpp index b7dc8705..374074d5 100644 --- a/sol/compatibility.hpp +++ b/sol/compatibility.hpp @@ -26,6 +26,9 @@ // comes from https://github.com/keplerproject/lua-compat-5.2 // but has been modified in many places for use with Sol and luajit, // though the core abstractions remain the same + +#ifndef SOL_NO_COMPAT + #include "compatibility/version.hpp" #ifdef __cplusplus extern "C" { @@ -38,4 +41,6 @@ extern "C" { } #endif +#endif // SOL_NO_COMPAT + #endif // SOL_COMPATIBILITY_HPP diff --git a/sol/compatibility/5.1.0.h b/sol/compatibility/5.1.0.h index d37bc078..a90cd5fa 100644 --- a/sol/compatibility/5.1.0.h +++ b/sol/compatibility/5.1.0.h @@ -144,6 +144,27 @@ void luaL_pushresult(luaL_Buffer_52 *B); #define luaL_pushresultsize(B, s) \ (luaL_addsize(B, s), luaL_pushresult(B)) +typedef struct kepler_lua_compat_get_string_view { + const char *s; + size_t size; +} kepler_lua_compat_get_string_view; + +inline const char* kepler_lua_compat_get_string(lua_State* L, void* ud, size_t* size) { + kepler_lua_compat_get_string_view* ls = (kepler_lua_compat_get_string_view*) ud; + (void)L; + if (ls->size == 0) return NULL; + *size = ls->size; + ls->size = 0; + return ls->s; +} + +inline int luaL_loadbufferx(lua_State* L, const char* buff, size_t size, const char* name, const char* mode) { + kepler_lua_compat_get_string_view ls; + ls.s = buff; + ls.size = size; + return lua_load(L, getS, &ls, name, mode); +} + #endif /* Lua 5.1 */ #endif // SOL_5_1_0_H \ No newline at end of file