Skip to content

Commit

Permalink
Merge pull request #321 from evo-lua/refactor-console-printf
Browse files Browse the repository at this point in the history
Move printf to the console library
  • Loading branch information
Duckwhale committed Oct 8, 2023
2 parents ca21187 + 521bba3 commit c9c3609
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Runtime/Libraries/console.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local buffer = require("string.buffer")
local validation = require("validation")
local validateString = validation.validateString

Expand Down Expand Up @@ -85,4 +86,8 @@ function console.clear()
end
end

function console.printf(...)
return print(format(...))
end

return console
7 changes: 2 additions & 5 deletions Runtime/evo.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local bdd = require("bdd")
local console = require("console")
local crypto = require("crypto")
local ffi = require("ffi")
local glfw = require("glfw")
Expand Down Expand Up @@ -81,7 +82,7 @@ function evo.registerGlobalAliases()
_G.format = string.format
_G.it = bdd.it

_G.printf = evo.printf
_G.printf = console.printf
_G.extend = evo.extend

_G.cdef = ffi.cdef
Expand Down Expand Up @@ -310,10 +311,6 @@ function evo.onInvalidCommand(command, argv)
evo.displayHelpText()
end

function evo.printf(...)
return print(format(...))
end

function evo.extend(child, parent)
local parentMetatable = getmetatable(parent)

Expand Down
9 changes: 9 additions & 0 deletions Tests/BDD/console-library.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ describe("console", function()
assert(elapsedTimeInMilliseconds >= 0)
end)
end)

describe("printf", function()
it("should support C-style format strings to output formatted text", function()
console.capture()
console.printf("Hello %s", "world")
local capturedOutput = console.release()
assertEquals(capturedOutput, "Hello world\n")
end)
end)
end)
4 changes: 2 additions & 2 deletions Tests/BDD/globals.spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local evo = require("evo")
local ffi = require("ffi")
local bdd = require("bdd")
local console = require("console")

local globalAliases = {
["buffer"] = require("string.buffer"),
Expand All @@ -10,7 +11,7 @@ local globalAliases = {
["format"] = string.format,
["it"] = bdd.it,
["path"] = require("path"),
["printf"] = evo.printf,
["printf"] = console.printf,
["cast"] = ffi.cast,
["cdef"] = ffi.cdef,
["define"] = ffi.cdef,
Expand Down Expand Up @@ -51,7 +52,6 @@ describe("_G", function()

describe("printf", function()
it("should output formatted strings to stdout", function()
local console = require("console")
console.capture()
printf("Hello %s", "printf")
local capturedOutput = console.release()
Expand Down

0 comments on commit c9c3609

Please sign in to comment.