VoxelEngine/src/logic/scripting/lua/lua_overrides.cpp
2024-10-05 00:53:41 +03:00

26 lines
805 B
C++

#include <iostream>
#include "libs/api_lua.hpp"
/// @brief Modified version of luaB_print from lbaselib.c
int l_print(lua::State* L) {
int n = lua::gettop(L); /* number of arguments */
lua::getglobal(L, "tostring");
for (int i = 1; i <= n; i++) {
lua::pushvalue(L, -1); /* function to be called */
lua::pushvalue(L, i); /* value to print */
lua::call(L, 1, 1);
const char* s = lua::tostring(L, -1); /* get result */
if (s == NULL)
return luaL_error(
L,
LUA_QL("tostring") " must return a string to " LUA_QL("print")
);
if (i > 1) std::cout << "\t";
std::cout << s;
lua::pop(L); /* pop result */
}
std::cout << std::endl;
return 0;
}