diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-28 15:42:34 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-28 15:42:34 -0200 |
| commit | 437a5b07d415e1a74160ddfd804017171d6cc5cb (patch) | |
| tree | 861f9a56ae175eaed91c163409c33ab85bee7ff9 /manual | |
| parent | ba7da13ec5938f978c37d63aa40a3e340b301f79 (diff) | |
| download | lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.tar.gz lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.tar.bz2 lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.zip | |
Added a warning system to Lua
The warning system is just a way for Lua to emit warnings, messages
to the programmer that do not interfere with the running program.
Diffstat (limited to 'manual')
| -rw-r--r-- | manual/manual.of | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/manual/manual.of b/manual/manual.of index 044bd09c..196ea1ef 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
| @@ -1795,7 +1795,7 @@ Functions with any detectable difference | |||
| 1795 | (different behavior, different definition) are always different. | 1795 | (different behavior, different definition) are always different. |
| 1796 | Functions created at different times but with no detectable differences | 1796 | Functions created at different times but with no detectable differences |
| 1797 | may be classified as equal or not | 1797 | may be classified as equal or not |
| 1798 | (depending on internal cashing details). | 1798 | (depending on internal caching details). |
| 1799 | 1799 | ||
| 1800 | You can change the way that Lua compares tables and userdata | 1800 | You can change the way that Lua compares tables and userdata |
| 1801 | by using the @idx{__eq} metamethod @see{metatable}. | 1801 | by using the @idx{__eq} metamethod @see{metatable}. |
| @@ -4033,6 +4033,16 @@ for the @Q{newindex} event @see{metatable}. | |||
| 4033 | 4033 | ||
| 4034 | } | 4034 | } |
| 4035 | 4035 | ||
| 4036 | @APIEntry{int lua_setiuservalue (lua_State *L, int index, int n);| | ||
| 4037 | @apii{1,0,-} | ||
| 4038 | |||
| 4039 | Pops a value from the stack and sets it as | ||
| 4040 | the new @id{n}-th user value associated to the | ||
| 4041 | full userdata at the given index. | ||
| 4042 | Returns 0 if the userdata does not have that value. | ||
| 4043 | |||
| 4044 | } | ||
| 4045 | |||
| 4036 | @APIEntry{void lua_setmetatable (lua_State *L, int index);| | 4046 | @APIEntry{void lua_setmetatable (lua_State *L, int index);| |
| 4037 | @apii{1,0,-} | 4047 | @apii{1,0,-} |
| 4038 | 4048 | ||
| @@ -4066,13 +4076,13 @@ If @id{index} @N{is 0}, then all stack elements are removed. | |||
| 4066 | 4076 | ||
| 4067 | } | 4077 | } |
| 4068 | 4078 | ||
| 4069 | @APIEntry{int lua_setiuservalue (lua_State *L, int index, int n);| | 4079 | @APIEntry{void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud);| |
| 4070 | @apii{1,0,-} | 4080 | @apii{0,0,-} |
| 4071 | 4081 | ||
| 4072 | Pops a value from the stack and sets it as | 4082 | Sets the @x{warning function} to be used by Lua to emit warnings |
| 4073 | the new @id{n}-th user value associated to the | 4083 | @see{lua_WarnFunction}. |
| 4074 | full userdata at the given index. | 4084 | The @id{ud} parameter initializes the slot @id{pud} passed to |
| 4075 | Returns 0 if the userdata does not have that value. | 4085 | the warning function. |
| 4076 | 4086 | ||
| 4077 | } | 4087 | } |
| 4078 | 4088 | ||
| @@ -4335,6 +4345,30 @@ Returns the version number of this core. | |||
| 4335 | } | 4345 | } |
| 4336 | 4346 | ||
| 4337 | @APIEntry{ | 4347 | @APIEntry{ |
| 4348 | typedef void (*lua_WarnFunction) (void **pud, const char *msg);| | ||
| 4349 | |||
| 4350 | The type of @x{warning function}s, called by Lua to emit warnings. | ||
| 4351 | The first parameter is the address of a writable slot, | ||
| 4352 | constant for a given Lua state and | ||
| 4353 | initialized by @Lid{lua_setwarnf}. | ||
| 4354 | The second parameter is the warning message. | ||
| 4355 | This function should assume that | ||
| 4356 | a message not ending with an end-of-line will be | ||
| 4357 | continued by the message in the next call. | ||
| 4358 | |||
| 4359 | } | ||
| 4360 | |||
| 4361 | @APIEntry{ | ||
| 4362 | void lua_warning (lua_State *L, const char *msg);| | ||
| 4363 | @apii{0,0,-} | ||
| 4364 | |||
| 4365 | Emits a warning with the given message. | ||
| 4366 | A message not ending with an end-of-line should be | ||
| 4367 | continued in another call to this function. | ||
| 4368 | |||
| 4369 | } | ||
| 4370 | |||
| 4371 | @APIEntry{ | ||
| 4338 | typedef int (*lua_Writer) (lua_State *L, | 4372 | typedef int (*lua_Writer) (lua_State *L, |
| 4339 | const void* p, | 4373 | const void* p, |
| 4340 | size_t sz, | 4374 | size_t sz, |
| @@ -4345,7 +4379,7 @@ Every time it produces another piece of chunk, | |||
| 4345 | @Lid{lua_dump} calls the writer, | 4379 | @Lid{lua_dump} calls the writer, |
| 4346 | passing along the buffer to be written (@id{p}), | 4380 | passing along the buffer to be written (@id{p}), |
| 4347 | its size (@id{sz}), | 4381 | its size (@id{sz}), |
| 4348 | and the @id{data} parameter supplied to @Lid{lua_dump}. | 4382 | and the @id{ud} parameter supplied to @Lid{lua_dump}. |
| 4349 | 4383 | ||
| 4350 | The writer returns an error code: | 4384 | The writer returns an error code: |
| 4351 | @N{0 means} no errors; | 4385 | @N{0 means} no errors; |
| @@ -6261,6 +6295,12 @@ The current value of this variable is @St{Lua 5.4}. | |||
| 6261 | 6295 | ||
| 6262 | } | 6296 | } |
| 6263 | 6297 | ||
| 6298 | @LibEntry{warn (message)| | ||
| 6299 | |||
| 6300 | Emits a warning with the given message. | ||
| 6301 | |||
| 6302 | } | ||
| 6303 | |||
| 6264 | @LibEntry{xpcall (f, msgh [, arg1, @Cdots])| | 6304 | @LibEntry{xpcall (f, msgh [, arg1, @Cdots])| |
| 6265 | 6305 | ||
| 6266 | This function is similar to @Lid{pcall}, | 6306 | This function is similar to @Lid{pcall}, |
