-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibuseful_errors.i
More file actions
83 lines (58 loc) · 1.28 KB
/
libuseful_errors.i
File metadata and controls
83 lines (58 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Copyright (c) 2019 Colum Paget <colums.projects@googlemail.com>
* SPDX-License-Identifier: GPL-3.0
*/
/*
This module implements access to the libUseful errors system. This is mostly useful for discovering
why a connection using a STREAM object failed and returned NULL/nil
usage:
errs=libuseful_errors.ERRORS()
str=errs:next()
while str ~= nil
do
print(str)
str=errs:next()
end
*/
%module libuseful_errors
%{
#include "libUseful-5/libUseful.h"
typedef struct
{
ListNode *Items;
} ERRORS;
%}
%init
%{
/* As lua uses garbage collection, and strings passed out of libUseful may not be*/
/* freed within libuseful before reuse, so we cannot use StrLen caching*/
LibUsefulSetValue("StrLenCache", "n");
%}
typedef struct
{
ListNode *Items;
} ERRORS;
%extend ERRORS {
ERRORS ()
{
ERRORS *Item;
Item=(ERRORS *) calloc(1, sizeof(ERRORS));
Item->Items=ErrorsGet();
return(Item);
}
~ERRORS ()
{
//do not free Item->Items as it is an internal libuseful list
free($self);
}
const char *next()
{
TError *Item;
if (! $self->Items->Side) $self->Items->Side=ListGetNext($self->Items);
else $self->Items->Side=ListGetNext($self->Items->Side);
//if we reached end of list, this will be NULL
if ($self->Items->Side==NULL) return(NULL);
Item=(TError *) $self->Items->Side->Item;
return(Item->msg);
}
}