Skip to content
Snippets Groups Projects
Commit 7633f522 authored by DarkGod's avatar DarkGod
Browse files

fix

parent 0837a0d0
No related branches found
No related tags found
No related merge requests found
...@@ -128,41 +128,41 @@ end ...@@ -128,41 +128,41 @@ end
function table.print_shallow(src, offset, line_feed) function table.print_shallow(src, offset, line_feed)
if not line_feed then line_feed = '\n' end if not line_feed then line_feed = '\n' end
if type(src) ~= "table" then io.stdout:write("table.print has no table:", src) io.stdout:write(line_feed) return end if type(src) ~= "table" then core.game.stdout_write("table.print has no table:", src) core.game.stdout_write(line_feed) return end
offset = offset or "" offset = offset or ""
for k, e in pairs(src) do for k, e in pairs(src) do
io.stdout:write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) io.stdout:write(line_feed) core.game.stdout_write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) core.game.stdout_write(line_feed)
end end
end end
function table.print(src, offset, line_feed) function table.print(src, offset, line_feed)
if not line_feed then line_feed = '\n' end if not line_feed then line_feed = '\n' end
if type(src) ~= "table" then io.stdout:write("table.print has no table:", src) io.stdout:write(line_feed) return end if type(src) ~= "table" then core.game.stdout_write("table.print has no table:", src) core.game.stdout_write(line_feed) return end
offset = offset or "" offset = offset or ""
for k, e in pairs(src) do for k, e in pairs(src) do
-- Deep copy subtables, but not objects! -- Deep copy subtables, but not objects!
if type(e) == "table" and not e.__ATOMIC and not e.__CLASSNAME then if type(e) == "table" and not e.__ATOMIC and not e.__CLASSNAME then
io.stdout:write(("%s[%s] = {"):format(offset, tostring(k))) io.stdout:write(line_feed) core.game.stdout_write(("%s[%s] = {"):format(offset, tostring(k))) core.game.stdout_write(line_feed)
table.print(e, offset.." ", line_feed) table.print(e, offset.." ", line_feed)
io.stdout:write(("%s}"):format(offset)) io.stdout:write(line_feed) core.game.stdout_write(("%s}"):format(offset)) core.game.stdout_write(line_feed)
else else
io.stdout:write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) io.stdout:write(line_feed) core.game.stdout_write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) core.game.stdout_write(line_feed)
end end
end end
end end
function table.iprint(src, offset, line_feed) function table.iprint(src, offset, line_feed)
if not line_feed then line_feed = '\n' end if not line_feed then line_feed = '\n' end
if type(src) ~= "table" then io.stdout:write("table.iprint has no table:", src) io.stdout:write(line_feed) return end if type(src) ~= "table" then core.game.stdout_write("table.iprint has no table:", src) core.game.stdout_write(line_feed) return end
offset = offset or "" offset = offset or ""
for k, e in ipairs(src) do for k, e in ipairs(src) do
-- Deep copy subtables, but not objects! -- Deep copy subtables, but not objects!
if type(e) == "table" and not e.__ATOMIC and not e.__CLASSNAME then if type(e) == "table" and not e.__ATOMIC and not e.__CLASSNAME then
io.stdout:write(("%s[%s] = {"):format(offset, tostring(k))) io.stdout:write(line_feed) core.game.stdout_write(("%s[%s] = {"):format(offset, tostring(k))) core.game.stdout_write(line_feed)
table.print(e, offset.." ") table.print(e, offset.." ")
io.stdout:write(("%s}"):format(offset)) io.stdout:write(line_feed) core.game.stdout_write(("%s}"):format(offset)) core.game.stdout_write(line_feed)
else else
io.stdout:write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) io.stdout:write(line_feed) core.game.stdout_write(("%s[%s] = %s"):format(offset, tostring(k), tostring(e))) core.game.stdout_write(line_feed)
end end
end end
end end
...@@ -170,11 +170,11 @@ end ...@@ -170,11 +170,11 @@ end
function tprint(...) function tprint(...)
local args = {...} local args = {...}
for i, str in ipairs(args) do for i, str in ipairs(args) do
if type(str) == "table" then io.stdout:write('{ ') table.print(str, nil, ', ') io.stdout:write(' }') if type(str) == "table" then core.game.stdout_write('{ ') table.print(str, nil, ', ') core.game.stdout_write(' }')
else io.stdout:write(tostring(str)) end else core.game.stdout_write(tostring(str)) end
if i < #args then io.stdout:write('\t') end if i < #args then core.game.stdout_write('\t') end
end end
io.stdout:write('\n') core.game.stdout_write('\n')
end end
--- Generate a containing indexes between a and b and set to value v --- Generate a containing indexes between a and b and set to value v
......
...@@ -608,6 +608,17 @@ static int lua_disable_connectivity(lua_State *L) ...@@ -608,6 +608,17 @@ static int lua_disable_connectivity(lua_State *L)
return 0; return 0;
} }
static int lua_stdout_write(lua_State *L)
{
int i = 1;
while (i <= lua_gettop(L)) {
const char *s = lua_tostring(L, i);
printf("%s", s);
i++;
}
return 0;
}
static int lua_open_browser(lua_State *L) static int lua_open_browser(lua_State *L)
{ {
#if defined(SELFEXE_LINUX) || defined(SELFEXE_BSD) #if defined(SELFEXE_LINUX) || defined(SELFEXE_BSD)
...@@ -647,6 +658,7 @@ static const struct luaL_Reg gamelib[] = ...@@ -647,6 +658,7 @@ static const struct luaL_Reg gamelib[] =
{"checkError", lua_check_error}, {"checkError", lua_check_error},
{"resetLocale", lua_reset_locale}, {"resetLocale", lua_reset_locale},
{"openBrowser", lua_open_browser}, {"openBrowser", lua_open_browser},
{"stdout_write", lua_stdout_write},
{"disableConnectivity", lua_disable_connectivity}, {"disableConnectivity", lua_disable_connectivity},
{NULL, NULL}, {NULL, NULL},
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment