From 8953ecec306536cd0b18c9de316461ad4c35166f Mon Sep 17 00:00:00 2001
From: Li Jin <dragon-fly@qq.com>
Date: Mon, 29 Nov 2021 14:42:36 +0800
Subject: fix issue #70.

---
 src/yue.cpp                    | 12 ++++++++++++
 src/yuescript/yue_compiler.cpp |  2 +-
 src/yuescript/yuescript.cpp    |  4 ++++
 3 files changed, 17 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/yue.cpp b/src/yue.cpp
index 1704b57..133a081 100644
--- a/src/yue.cpp
+++ b/src/yue.cpp
@@ -37,7 +37,12 @@ int luaopen_yue(lua_State* L);
 static void openlibs(void* state) {
 	lua_State* L = static_cast<lua_State*>(state);
 	luaL_openlibs(L);
+#if LUA_VERSION_NUM > 501
 	luaL_requiref(L, "yue", luaopen_yue, 1);
+#else
+	lua_pushcfunction(L, luaopen_yue);
+	lua_call(L, 0, 0);
+#endif
 	lua_pop(L, 1);
 }
 
@@ -238,7 +243,14 @@ int main(int narg, const char** args) {
 			if (success) {
 				if (retCount > 1) {
 					for (int i = 1; i < retCount; ++i) {
+#if LUA_VERSION_NUM > 501
 						std::cout << Val << luaL_tolstring(L, -retCount + i, nullptr) << Stop;
+#else // LUA_VERSION_NUM
+						lua_getglobal(L, "tostring");
+						lua_pushvalue(L, -retCount + i - 1);
+						lua_call(L, 1, 1);
+						std::cout << Val << lua_tostring(L, -1) << Stop;
+#endif // LUA_VERSION_NUM
 						lua_pop(L, 1);
 					}
 				}
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index d4996a7..e93324e 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
 
 typedef std::list<std::string> str_list;
 
-const std::string_view version = "0.9.2"sv;
+const std::string_view version = "0.9.3"sv;
 const std::string_view extension = "yue"sv;
 
 class YueCompilerImpl {
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp
index b83a454..87aa917 100644
--- a/src/yuescript/yuescript.cpp
+++ b/src/yuescript/yuescript.cpp
@@ -133,7 +133,11 @@ static const luaL_Reg yuelib[] = {
 };
 
 int luaopen_yue(lua_State* L) {
+#if LUA_VERSION_NUM > 501
 	luaL_newlib(L, yuelib); // yue
+#else
+	luaL_register(L, "yue", yuelib); // yue
+#endif
 	lua_pushlstring(L, &yue::version.front(), yue::version.size()); // yue version
 	lua_setfield(L, -2, "version"); // yue["version"] = version, yue
 	lua_createtable(L, 0, 0); // yue options
-- 
cgit v1.2.3-55-g6feb