diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2015-04-25 21:34:17 +0200 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2015-04-25 21:34:17 +0200 |
commit | c4a98dafd07ed28e8f05d8771de65ce18ba0bee7 (patch) | |
tree | 4fce6a41b1ef2f96f59e3eca18e16141cef8abdd | |
parent | 67dd52ab4ee97cf644ed4540df14c9619b50d0af (diff) | |
download | lua-compat-5.3-c4a98dafd07ed28e8f05d8771de65ce18ba0bee7.tar.gz lua-compat-5.3-c4a98dafd07ed28e8f05d8771de65ce18ba0bee7.tar.bz2 lua-compat-5.3-c4a98dafd07ed28e8f05d8771de65ce18ba0bee7.zip |
Document changes to compat53.module in readme.
-rw-r--r-- | README.md | 29 |
1 files changed, 10 insertions, 19 deletions
@@ -45,27 +45,18 @@ versions of the new `table` functions are used as a fallback, and | |||
45 | #### Lua submodules | 45 | #### Lua submodules |
46 | 46 | ||
47 | ```lua | 47 | ```lua |
48 | local compat53 = require("compat53.base") | 48 | local _ENV = require("compat53.module") |
49 | if setfenv then setfenv(1, _ENV) end | ||
49 | ``` | 50 | ``` |
50 | 51 | ||
51 | This loads the compatibility functions and returns them in a table | 52 | The `compat53.module` module does not modify the global environment, |
52 | without modifying the global environment. The returned table has a | 53 | and so it is safe to use in modules without affecting other Lua files. |
53 | metatable set so that lookup of unmodified global functions should | 54 | It is supposed to be set as the current environment (see above), i.e. |
54 | work as well. Some features (e.g. file methods) of `compat53` only | 55 | cherry picking individual functions from this module is expressly |
55 | take effect when applied to the global environment though, and groups | 56 | *not* supported!). Not all features are available when using this |
56 | of functions might be interdependent and should not be mixed with old | 57 | module (e.g. yieldable (x)pcall support, string/file methods, etc.), |
57 | versions of those functions. (I.e. it is recommended to use plain | 58 | so it is recommended to use plain `require("compat53")` whenever |
58 | `require("compat53")` when possible!) | 59 | possible. |
59 | |||
60 | ```lua | ||
61 | require("compat53.module") | ||
62 | ``` | ||
63 | |||
64 | This looks in the call stack for the closest "main" chunk (module or | ||
65 | script) and replaces its environment so that you can transparently use | ||
66 | the compatibility functions in this file alone without affecting other | ||
67 | files. The same gotchas as for `"compat53.base"` apply. Additionally | ||
68 | this relies on the availability of `debug` functions. | ||
69 | 60 | ||
70 | ### C code | 61 | ### C code |
71 | 62 | ||