Skip to content

Instantly share code, notes, and snippets.

@JamesxX
Created February 11, 2017 15:10
Show Gist options
  • Save JamesxX/a6841e522957b3f38f3b1120a33f20e5 to your computer and use it in GitHub Desktop.
Save JamesxX/a6841e522957b3f38f3b1120a33f20e5 to your computer and use it in GitHub Desktop.
Promise functions to native libraries, that can be redefined at any point
--[[
Virtual functions - Lua
]]
local vfunc = { }
function PromiseVirtualFunction( sFunctionName )
return function( ... )
if (vfunc[sFunctionName]) return vfunc[sFunctionName]( ... ) end
error( string.format( "Promised function %s was nil", sFunctionName ) )
end
end
function DefinePromisedFunction( sFunctionName, func )
vfunc[sFunctionName] = func
end
-- Example use
timer.Simple( 1, PromiseVirtualFunction( "MyPromisedFunction" ))
DefinePromisedFunction( "MyPromisedFunction", function() print("Hello from promised function") end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment