IceGT_'s Hook System and Table extensions
Posted: Wed Jan 11, 2017 7:59 am
Hi, this would be my first post. What I have to offer is...
Hooks - https://github.com/icegt95/icegts_love2 ... e_hook.lua
...another hook system that I'm currently using in a project I hope to get greenlit this year, which is kinda like the one GMod uses, but kinda not - the main difference being that hook.call will return a table of all values returned by any called hook. hook.run will return the first value it receives. The system can be modified easily to perform differently if need be.
Table library extension - https://github.com/icegt95/icegts_love2 ... _table.lua
Expands on lua's table library with functions similar to those in Garry's Mod.
Hooks - https://github.com/icegt95/icegts_love2 ... e_hook.lua
...another hook system that I'm currently using in a project I hope to get greenlit this year, which is kinda like the one GMod uses, but kinda not - the main difference being that hook.call will return a table of all values returned by any called hook. hook.run will return the first value it receives. The system can be modified easily to perform differently if need be.
Code: Select all
-- Example 1:
hook.add( "ShouldSkipStartupMessage", "blocking_1", function()
return true
end )
love.load = function()
local should_skip = hook.run( "ShouldSkipStartupMessage" )
if not ( should_skip == true ) then -- for demonstration purposes
print( "Startup message wasn't skipped" )
end
end
-- Example 2:
hook.add( "LoveGameStartOrSomething", "ex2_hooka", function( num1, num2, num3 )
return "Random numbers to format for results_tab - " .. num1 .. ", " .. num2 .. ", " .. num3 .. "!"
end )
hook.add( "LoveGameStartOrSomething", "ex2_hookb", function( num1, num2, num3 )
return "This will also be returned in results_tab - " .. num1 .. ", " .. num2 .. ", " .. num3 .. "!"
end )
love.load = function()
local results_tab = hook.call( "LoveGameStartOrSomething", math.random(), math.random(), math.random() )
if results_tab then
for idx, res_str in next, results_tab, nil do
print( res_str )
end
end
end
Expands on lua's table library with functions similar to those in Garry's Mod.