summaryrefslogtreecommitdiff
path: root/src/bindings/luajit/eolian.lua
blob: 391d227762eb2824f1101ac25e2666e2d694dcd9 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
-- EFL LuaJIT bindings: Eolian
-- For use with Elua

local ffi = require("ffi")

ffi.cdef [[
    typedef unsigned char Eina_Bool;
    typedef struct _Eina_List Eina_List;

    typedef struct _Eolian_Function Eolian_Function;
    typedef struct _Eolian_Function_Parameter Eolian_Function_Parameter;
    typedef struct _Eolian_Implement Eolian_Implement;
    typedef struct _Eolian_Implement_Legacy Eolian_Implement_Legacy;
    typedef struct _Eolian_Implement_Legacy_Parameter Eolian_Implement_Legacy_Parameter;
    typedef struct _Eolian_Event Eolian_Event;

    typedef enum
    {
       EOLIAN_UNRESOLVED,
       EOLIAN_PROPERTY,
       EOLIAN_PROP_SET,
       EOLIAN_PROP_GET,
       EOLIAN_METHOD,
       EOLIAN_CTOR,
       EOLIAN_DTOR,
       EOLIAN_DFLT_CTOR,
       EOLIAN_DFLT_DTOR
    } Eolian_Function_Type;

    typedef enum
    {
       EOLIAN_IN_PARAM,
       EOLIAN_OUT_PARAM,
       EOLIAN_INOUT_PARAM
    } Eolian_Parameter_Dir;

    typedef enum
    {
       EOLIAN_CLASS_UNKNOWN_TYPE,
       EOLIAN_CLASS_REGULAR,
       EOLIAN_CLASS_ABSTRACT,
       EOLIAN_CLASS_MIXIN,
       EOLIAN_CLASS_INTERFACE
    } Eolian_Class_Type;

    typedef enum
    {
       EOLIAN_SCOPE_PUBLIC,
       EOLIAN_SCOPE_PROTECTED
    } Eolian_Function_Scope;

    Eina_Bool eolian_eo_file_parse(const char *filename);
    int eolian_init(void);
    int eolian_shutdown(void);
    Eina_Bool eolian_show(const char *class_name);
    const char *eolian_class_find_by_file(const char *file_name);
    Eolian_Class_Type eolian_class_type_get(const char *class_name);
    const Eina_List *eolian_class_names_list_get(void);
    Eina_Bool eolian_class_exists(const char *class_name);
    const char *eolian_class_description_get(const char *class_name);
    const char *eolian_class_legacy_prefix_get(const char *class_name);
    const char* eolian_class_eo_prefix_get(const char *class_name);
    const char*eolian_class_data_type_get(const char *class_name);
    const Eina_List *eolian_class_inherits_list_get(const char *class_name);
    const Eina_List *eolian_class_functions_list_get(const char *class_name, Eolian_Function_Type func_type);
    Eolian_Function *eolian_class_default_constructor_get(const char *class_name);
    Eolian_Function *eolian_class_default_destructor_get(const char *class_name);
    Eolian_Function_Type eolian_function_type_get(Eolian_Function *function_id);
    Eolian_Function_Scope eolian_function_scope_get(Eolian_Function *function_id);
    const char *eolian_function_name_get(Eolian_Function *function_id);
    Eolian_Function *eolian_class_function_find_by_name(const char *classname, const char *func_name, Eolian_Function_Type f_type);
    const char *eolian_function_data_get(Eolian_Function *function_id, const char *key);
    Eina_Bool eolian_function_is_virtual_pure(Eolian_Function *function_id, Eolian_Function_Type f_type);
    Eolian_Function_Parameter *eolian_function_parameter_get(const Eolian_Function *function_id, const char *param_name);
    const Eina_List *eolian_property_keys_list_get(Eolian_Function *foo_id);
    const Eina_List *eolian_property_values_list_get(Eolian_Function *foo_id);
    const Eina_List *eolian_parameters_list_get(Eolian_Function *function_id);
    void eolian_parameter_information_get(Eolian_Function_Parameter *param_desc, Eolian_Parameter_Dir *param_dir, const char **type, const char **name, const char **description);
    const char *eolian_parameter_type_get(const Eolian_Function_Parameter *param);
    const char *eolian_parameter_name_get(const Eolian_Function_Parameter *param);
    Eina_Bool eolian_parameter_const_attribute_get(Eolian_Function_Parameter *param_desc, Eina_Bool is_get);
    Eina_Bool eolian_parameter_is_nonull(Eolian_Function_Parameter *param_desc);
    Eina_Bool eolian_parameter_is_own(Eolian_Function_Parameter *param_desc);
    const char *eolian_function_return_type_get(Eolian_Function *function_id, Eolian_Function_Type ftype);
    const char *eolian_function_return_dflt_value_get(Eolian_Function *foo_id, Eolian_Function_Type ftype);
    const char *eolian_function_return_comment_get(Eolian_Function *foo_id, Eolian_Function_Type ftype);
    Eina_Bool eolian_function_return_is_warn_unused(Eolian_Function *foo_id, Eolian_Function_Type ftype);
    Eina_Bool eolian_function_return_own_get(Eolian_Function *foo_id, Eolian_Function_Type ftype);
    Eina_Bool eolian_function_object_is_const(Eolian_Function *function_id);
    Eina_Bool eolian_implement_information_get(Eolian_Implement *impl, const char **class_name, const char **func_name, Eolian_Function_Type *type);
    const Eina_List *eolian_class_implements_list_get(const char *class_name);
    const Eina_List *eolian_class_events_list_get(const char *class_name);
    Eina_Bool eolian_class_event_information_get(Eolian_Event *event, const char **event_name, const char **event_type, const char **event_desc);
    Eina_Bool eolian_class_ctor_enable_get(const char *class_name);
    Eina_Bool eolian_class_dtor_enable_get(const char *class_name);
]]

local cutil = require("cutil")
local util  = require("util")

local list = require("eina.list")

local M = {}

local eolian

local init = function()
    eolian = util.lib_load("eolian")
    eolian.eolian_init()
end

local shutdown = function()
    eolian.eolian_shutdown()
    util.lib_unload("eolian")
end

cutil.init_module(init, shutdown)

M.eo_file_parse = function(fname)
    return eolian.eolian_eo_file_parse(fname) ~= 0
end

M.show = function(cname)
    return eolian.eolian_show(cname) ~= 0
end

M.class_find_by_file = function(fname)
    local v = eolian.eolian_class_find_by_file(fname)
    if v == nil then return nil end
    return ffi.string(v)
end

M.class_type = {
    UNKNOWN   = 0,
    REGULAR   = 1,
    ABSTRACT  = 2,
    MIXIN     = 3,
    INTERFACE = 4
}

M.class_type_get = function(cname)
    return eolian.eo_class_type_get(cname)
end

M.class_names_list_get = function()
    return list.String_List(eolian.eolian_class_names_list_get()):to_array()
end

M.class_exists = function(cname)
    return eolian.eolian_class_exists(cname) ~= 0
end

M.class_description_get = function(cname)
    local v = eolian.eolian_class_description_get(cname)
    if v == nil then return nil end
    return ffi.string(v)
end

M.class_legacy_prefix_get = function(cname)
    local v = eolian.eolian_class_legacy_prefix_get(cname)
    if v == nil then return nil end
    return ffi.string(v)
end

M.class_eo_prefix_get = function(cname)
    local v = eolian.eolian_class_eo_prefix_get(cname)
    if v == nil then return nil end
    return ffi.string(v)
end

M.class_data_type_get = function(cname)
    local v = eolian.eolian_class_data_type_get(cname)
    if v == nil then return nil end
    return ffi.string(v)
end

M.class_inherits_list_get = function(cname)
    return list.String_List(eolian.eolian_class_inherits_list_get(cname))
        :to_array()
end

local List_Base = list.List_Base

local Eolian_Functions_List = List_Base:clone {
    data_get = function(self, ptr)
        ptr = List_Base.data_get(self, ptr)
        return ffi.cast("Eolian_Function*", ptr)
    end
}

M.function_type = {
    UNRESOLVED = 0,
    PROPERTY   = 1,
    PROP_SET   = 2,
    PROP_GET   = 3,
    METHOD     = 4,
    CTOR       = 5,
    DTOR       = 6,
    DFLT_CTOR  = 7,
    DFLT_DTOR  = 8
}

M.function_scope = {
    PUBLIC    = 0,
    PROTECTED = 1
}

M.class_functions_list_get = function(cname, func_type)
    return Eolian_Functions_List(eolian.eolian_class_functions_list_get(cname),
        func_type):to_array()
end

M.class_default_constructor_get = function(cname)
    local v = eolian.eolian_class_default_constructor_get(cname)
    if v == nil then return nil end
    return v
end

M.class_default_destructor_get = function(cname)
    local v = eolian.eolian_class_default_destructor_get(cname)
    if v == nil then return nil end
    return v
end

local Eolian_Parameters_List = List_Base:clone {
    data_get = function(self, ptr)
        ptr = List_Base.data_get(self, ptr)
        return ffi.cast("Eolian_Function_Parameter*", ptr)
    end
}

M.Function = ffi.metatype("Eolian_Function", {
    __index = {
        find_by_name = function(cname, fname, ftype)
            local v = eolian.eolian_class_function_find_by_name(cname, fname,
                ftype)
            if v == nil then return nil end
            return v
        end,

        type_get = function(self)
            return eolian.eolian_function_type_get(self)
        end,

        scope_get = function(self)
            return eolian.eolian_function_scope_get(self)
        end,

        name_get = function(self)
            local v = eolian.eolian_function_name_get(self)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        data_get = function(self, key)
            local v = eolian.eolian_function_data_get(self, key)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        description_get = function(self, key)
            return self:data_get(key)
        end,

        is_virtual_pure = function(self, ftype)
            return eolian.eolian_function_is_virtual_pure(self, ftype) ~= 0
        end,

        parameter_get = function(self, pname)
            local v = eolian.eolian_function_parameter_get(self, pname)
            if v == nil then return nil end
            return v
        end,

        property_keys_list_get = function(self)
            return Eolian_Parameters_List(
                eolian.eolian_propety_keys_list_get(self)):to_array()
        end,

        property_values_list_get = function(self)
            return Eolian_Parameters_List(
                eolian.eolian_propety_values_list_get(self)):to_array()
        end,

        parameters_list_get = function(self)
            return Eolian_Parameters_List(
                eolian.eolian_parameters_list_get(self)):to_array()
        end,

        return_type_get = function(self, ftype)
            local v = eolian.eolian_function_return_type_get(self, ftype)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        return_dflt_value_get = function(self, ftype)
            local v = eolian.eolian_function_return_dflt_value_get(self, ftype)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        return_comment_get = function(self, ftype)
            local v = eolian.eolian_function_return_comment_get(self, ftype)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        return_is_warn_unused = function(self, ftype)
            return eolian.eolian_function_return_is_warn_unused(self,
                ftype) ~= 0
        end,

        return_own_get = function(self, ftype)
            return eolian.eolian_function_return_own_get(self, ftype) ~= 0
        end,

        is_const = function(self)
            return eolian.eolian_function_object_is_const(self) ~= 0
        end
    }
})

M.parameter_dir = {
    IN_PARAM    = 0,
    OUT_PARAM   = 1,
    INOUT_PARAM = 2
}

ffi.metatype("Eolian_Function_Parameter", {
    __index = {
        information_get = function(self)
            local dir = ffi.new("Eolian_Parameter_Dir[1]")
            local str = ffi.new("const char*[3]")
            eolian.eolian_parameter_get(self, dir, str, str + 1, str + 1)
            local tp, nm, dsc = str[0], str[1], str[2]
            tp, nm, dsc = (tp  ~= nil) and ffi.string(tp ) or nil,
                          (nm  ~= nil) and ffi.string(nm ) or nil,
                          (dsc ~= nil) and ffi.string(dsc) or nil
            return dir[0], tp, nm, dsc
        end,

        type_get = function(self)
            local v = eolian.eolian_parameter_type_get(self)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        name_get = function(self)
            local v = eolian.eolian_parameter_name_get(self)
            if v == nil then return nil end
            return ffi.string(v)
        end,

        const_attribute_get = function(self, get)
            return eolian.eolian_parameter_const_attribute_get(self, get) ~= 0
        end,

        is_nonull = function(self)
            return eolian.eolian_parameter_is_nonull(self) ~= 0
        end,

        is_own = function(self)
            return eolian.eolian_parameter_is_own(self) ~= 0
        end
    }
})

local Eolian_Implements_List = List_Base:clone {
    data_get = function(self, ptr)
        ptr = List_Base.data_get(self, ptr)
        return ffi.cast("Eolian_Implement*", ptr)
    end
}

ffi.metatype("Eolian_Implement", {
    __index = {
        information_get = function(self)
            local nm = ffi.new("const char*[2]")
            local tp = ffi.new("Eolian_Function_Type[1]")
            eolian.eolian_implement_information_get(self, nm, nm + 1, tp)
            local cn, fn = nm[0], nm[1]
            cn, fn = (cn ~= nil) and ffi.string(cn) or nil,
                     (fn ~= nil) and ffi.string(fn) or nil
            return cn, fn, tp[0]
        end
    }
})

M.class_implements_list_get = function(cname)
    return Eolian_Implements_List(
        eolian.eolian_class_implements_list_get(cname)):to_array()
end

local Eolian_Events_List = List_Base:clone {
    data_get = function(self, ptr)
        ptr = List_Base.data_get(self, ptr)
        return ffi.cast("Eolian_Event*", ptr)
    end
}

ffi.metatype("Eolian_Event", {
    __index = {
        information_get = function(self)
            local ev = ffi.new("const char*[3]")
            eolian.eolian_class_event_information_get(self, ev, ev + 1, ev + 2)
            local en, et, ed = ev[0], ev[1], ev[2]
            en, et, ed = (en ~= nil) and ffi.string(en) or nil,
                         (et ~= nil) and ffi.string(et) or nil,
                         (ed ~= nil) and ffi.string(ed) or nil
            return en, et, ed
        end
    }
})

M.class_events_list_get = function(cname)
    return Eolian_Events_List(
        eolian.eolian_class_events_list_get(cname)):to_array()
end

M.class_ctor_enable_get = function(cname)
    return eolian.eolian_class_ctor_enable_get(cname) ~= 0
end

M.class_dtor_enable_get = function(cname)
    return eolian.eolian_class_dtor_enable_get(cname) ~= 0
end

return M