summaryrefslogtreecommitdiff
path: root/tests/libpeas/plugins/extension-lua/extension-lua51.lua
blob: 4b97a30475ba6b43f25900d16ff54d0a3db9504e (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
--
--  Copyright (C) 2014 - Garrett Regier
--
-- libpeas is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- libpeas is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.

local lgi = require 'lgi'

local GObject = lgi.GObject
local Introspection = lgi.Introspection
local Peas = lgi.Peas


local ExtensionLuaPlugin = GObject.Object:derive('ExtensionLuaPlugin', {
    Peas.Activatable,
    Introspection.Base,
    Introspection.Callable,
    Introspection.HasPrerequisite
})

ExtensionLuaPlugin._property.object =
    GObject.ParamSpecObject('object', 'object', 'object',
                            GObject.Object._gtype,
                            { GObject.ParamFlags.READABLE,
                              GObject.ParamFlags.WRITABLE })

ExtensionLuaPlugin._property.update_count =
    GObject.ParamSpecInt('update-count', 'update-count', 'update-count',
                         0, 1000000, 0,
                         { GObject.ParamFlags.READABLE })

function ExtensionLuaPlugin:_init()
    self.priv.update_count = 0
end

function ExtensionLuaPlugin:do_activate()
    collectgarbage('restart')
end

function ExtensionLuaPlugin:do_deactivate()
    collectgarbage('stop')
end

function ExtensionLuaPlugin:do_update_state()
    self.priv.update_count = self.priv.update_count + 1
end

function ExtensionLuaPlugin:do_get_plugin_info()
    return self.priv.plugin_info
end

function ExtensionLuaPlugin:do_get_settings()
    return self.priv.plugin_info:get_settings(nil)
end

function ExtensionLuaPlugin:do_call_no_args()
end

function ExtensionLuaPlugin:do_call_with_return()
    return 'Hello, World!'
end

function ExtensionLuaPlugin:do_call_single_arg()
    return true
end

function ExtensionLuaPlugin:do_call_multi_args(in_, inout)
    return inout, in_
end

-- Test strict mode
local UNIQUE = {}

local function assert_error(success, result)
    assert(not success, result)
end

assert_error(pcall(function() _G[UNIQUE] = true end))
assert(pcall(function()
    rawset(_G, UNIQUE, true)
    assert(_G[UNIQUE] == true)
    _G[UNIQUE] = nil
end))
assert_error(pcall(function() _G[UNIQUE] = true end))
assert(pcall(function()
    __STRICT = false
    _G[UNIQUE] = true
    _G[UNIQUE] = nil
    __STRICT = true
end))

return { ExtensionLuaPlugin }

-- ex:set ts=4 et sw=4 ai: