Skip to content

Commit

Permalink
Merge pull request #6 from konsumer/patch-2
Browse files Browse the repository at this point in the history
Example usage (related to #5)
  • Loading branch information
MrcSnm authored Nov 12, 2021
2 parents 55ed843 + 4c41ad8 commit 3a14f99
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ git submodule update --init --recursive
- Now just `require "REST"`, it defines a global named `REST`
- If you wish to use **module-loader** into your project, just delete the `require module-loader` from REST.lua (First line)

## Simple Example

Here is a simple example of using it in a love-game. Let's imagine you have recursive-cloned this repo to a sub-folder in your game: `lib/REST-love`:

```lua
-- this lets you require things with different paths other than root
require "lib.REST-love.module-loader"

-- this adds REST global
requireFromLib("lib/REST-love", "REST")

function love.load()
REST.get("https://mycoolserver.com/api", nil, function(data)
-- Do something here with data. It's text.
end)
end

function love.update(dt)
-- this is needed to trigger pending callbacks
-- it's wrapped with pcall to prevent it from crashing game
pcall(function() REST.retrieve(dt) end)
end
```


## AsyncLoader
AsyncLoader(Actually CoroutineLoader) is meant to be used by the LoadBar module, but you can extend its use yourself, you can use that
to do any heavy and synchronous operation for thiner operations, this is a Singleton, don't extend it unless
Expand Down

0 comments on commit 3a14f99

Please sign in to comment.