Trying to fix tostring

This commit is contained in:
Cooldude2606
2017-09-15 19:16:07 +01:00
parent dd0c13d64a
commit 9c4600377a
5 changed files with 10 additions and 10 deletions

View File

@@ -65,7 +65,7 @@ See code for more details.
* Convert ticks to hours based on game speed
* tick_to_min (tick)
* Convert ticks to minutes based on game speed
* table.to_string(tbl)
* table.tostring(tbl)
* We stole this but we don't know from where, just google it
* output -> table as a string
## Get Commands

View File

@@ -68,23 +68,23 @@ function load_command(command)
local player = game.players[event.player_index]
if not rank_allowed(get_rank(player),command.name) then
player.print('401 - Unauthorized: Access is denied due to invalid credentials')
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.to_string(get_command_args(event,command,true)), true, 0)
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
return
end
local args = get_command_args(event,command)
if args == 'Invalid' then
player.print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Invalid Args): '..command.name..' With args of: '..table.to_string(get_command_args(event,command,true)), true, 0)
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Invalid Args): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
end
command.event(player,event,args)
player.print('Command Complete')
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Used command: '..command.name..' With args of: '..table.to_string(args), true, 0)
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
else
local args = get_command_args(event,command)
if args == 'Invalid' then print('Invalid Input, /'..command.name..' '..command_inputs_to_string(command)) return end
command.event('<server>',event,args)
print('Command Complete')
game.write_file('commands.log','\n'..game.tick..' Player: <server> Used command: '..command.name..' With args of: '..table.to_string(args), true, 0)
game.write_file('commands.log','\n'..game.tick..' Player: <server> Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
end
end)
end

View File

@@ -43,7 +43,7 @@ function table.val_to_str ( v )
end
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
else
return "table" == type( v ) and table.to_string( v ) or
return "table" == type( v ) and table.tostring( v ) or
tostring( v )
end
end
@@ -56,7 +56,7 @@ function table.key_to_str ( k )
end
end
function table.to_string( tbl )
function table.tostring( tbl )
local result, done = {}, {}
for k, v in ipairs( tbl ) do
table.insert( result, table.val_to_str( v ) )

View File

@@ -22,11 +22,11 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits
define_command('server-interface','For use of the highest staff only',{'command',true},function(player,event,args)
if player == '<server>' then
local returned,value = pcall(loadstring(event.parameter))
if type(value) == 'table' then game.write_file('server-interface.log', '\n'..game.tick..' Ran by: <server> Code: '..event.parameter..'\n Returned: '..table.to_string(value), true, 0) print(table.to_string(value))
if type(value) == 'table' then game.write_file('server-interface.log', '\n'..game.tick..' Ran by: <server> Code: '..event.parameter..'\n Returned: '..table.tostring(value), true, 0) print(table.tostring(value))
else game.write_file('server-interface.log', '\n'..game.tick..' Ran by: <server> Code: '..event.parameter..'\nReturned: '..tostring(value), true, 0) print(value) end
else
local returned,value = pcall(loadstring(event.parameter))
if type(value) == 'table' then game.write_file('server-interface-players.log', '\n'..game.tick..' Ran by: '..player.name..' Code: '..event.parameter..'\n Returned: '..table.to_string(value), true, 0) player.print(table.to_string(value))
if type(value) == 'table' then game.write_file('server-interface-players.log', '\n'..game.tick..' Ran by: '..player.name..' Code: '..event.parameter..'\n Returned: '..table.tostring(value), true, 0) player.print(table.tostring(value))
else game.write_file('server-interface-players.log', '\n'..game.tick..' Ran by: '..player.name..' Code: '..event.parameter..'\nReturned: '..tostring(value), true, 0) player.print(value) end
end
end)

View File

@@ -62,7 +62,7 @@ function draw_frame.popup(style,args)
local args = args or {}
local frame_data = nil
for _,frame in pairs(frames.popup) do if style == frame.style then frame_data = frame break end end
game.write_file('popups.log','\n'..game.tick..' Popup Style: '..style..' Was made with args of: '..table.to_string(args), true, 0)
game.write_file('popups.log','\n'..game.tick..' Popup Style: '..style..' Was made with args of: '..table.tostring(args), true, 0)
for _,player in pairs(game.connected_players) do
local popups = mod_gui.get_frame_flow(player).popups
local frame = get_next_popup(popups)