File: init.lua

package info (click to toggle)
mame 0.284%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 928,352 kB
  • sloc: cpp: 5,466,696; xml: 2,242,157; ansic: 752,116; sh: 34,431; lisp: 19,643; python: 17,598; makefile: 13,259; java: 8,492; yacc: 8,152; javascript: 7,147; cs: 6,013; asm: 4,786; ada: 1,681; pascal: 1,191; lex: 1,174; perl: 585; ruby: 373
file content (91 lines) | stat: -rw-r--r-- 1,938 bytes parent folder | download | duplicates (2)
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
-- license:BSD-3-Clause
-- copyright-holders:Carl
-- A data script should contain two functions check which takes a set name and returns the data
-- heading if it supports the set otherwise nil and get which returns the data
-- the script should be named data_<name>.lua
-- this is set default on in the plugin.json
local exports = {
	name = 'data',
	version = '0.0.2',
	description = 'Data plugin',
	license = 'BSD-3-Clause',
	author = { name = 'Carl' } }

local data = exports

local plugindir

local reset_subscription

function data.set_folder(path)
	plugindir = path
end

function data.startplugin()
	local data_scr = {}
	local valid_lst = {}
	local cur_set
	local cur_list

	reset_subscription = emu.add_machine_reset_notifier(
			function ()
				data_scr = {}
				for file in lfs.dir(plugindir) do
					local name = string.match(file, '^(data_.*).lua$')
					if name then
						local script = require('data/' .. name)
						if script then
							table.insert(data_scr, script)
						end
					end
				end
			end)

	emu.register_callback(
			function (set)
				local ret = {}
				if set == '' then
					set = emu.romname()
				end
				if set == cur_set then
					return cur_list
				end
				cur_set = set
				if not set then
					return nil
				end
				valid_lst = {}
				for num, scr in ipairs(data_scr) do
					local setname, softname = set:match('^([^,]+),?(.*)$')
					if softname == '' then
						softname = nil
					end
					local name = scr.check(setname, softname)
					if name then
						table.insert(ret, name)
						table.insert(valid_lst, scr)
					end
				end
				cur_list = ret
				return ret
			end,
			'data_list')

	emu.register_callback(
			function (num)
				return valid_lst[num + 1].get()
			end,
			'data')

	emu.register_callback(
			function (num)
				local ver
				if valid_lst[num + 1].ver then
					ver = valid_lst[num + 1].ver()
				end
				return ver or ''
			end,
			'data_version')
end

return exports