View difference between Paste ID: aJUcZC8s and bQfzfrQx
SHOW: | | - or go back to the newest paste.
1-
-- Liste tous les peripheriques connectes
1+
-- Liste tous les périphériques connectés
2
local periphs = peripheral.getNames()
3
4-
print("Peripheriques detectes :")
4+
print("Detected peripherals:")
5-
for _, name in ipairs(periphs) do
5+
for i, name in ipairs(periphs) do
6
    local pType = peripheral.getType(name)
7-
    print("- " .. name .. " (" .. pType .. ")")
7+
    print(i .. ". " .. name .. " (" .. pType .. ")")
8
end
9
10
-- Demande à l'utilisateur de choisir un périphérique
11
print()
12
write("Enter the number of the peripheral to inspect: ")
13
local choice = tonumber(read())
14
15
if not choice or choice < 1 or choice > #periphs then
16
    print("Invalid choice.")
17
    return
18
end
19
20
local selectedName = periphs[choice]
21
local selectedPeripheral = peripheral.wrap(selectedName)
22
23
if not selectedPeripheral then
24
    print("Failed to wrap peripheral: " .. selectedName)
25
    return
26
end
27
28
-- Récupère la liste des fonctions du périphérique
29
local functions = {}
30
for k, v in pairs(selectedPeripheral) do
31
    if type(v) == "function" then
32
        table.insert(functions, k)
33
    end
34
end
35
36
-- Trie les fonctions par ordre alphabétique
37
table.sort(functions)
38
39
-- Affiche la liste des fonctions
40
print()
41
print("Functions available on " .. selectedName .. ":")
42
for i, fn in ipairs(functions) do
43
    print("- " .. fn)
44
end
45
46
-- Demande à l'utilisateur s'il veut sauvegarder la liste
47
print()
48
write("Enter a filename to save the list (or leave blank to skip): ")
49
local filename = read()
50
51
if filename ~= "" then
52
    local file = fs.open(filename, "w")
53
    file.writeLine("Functions available on " .. selectedName .. ":")
54
    for i, fn in ipairs(functions) do
55
        file.writeLine("- " .. fn)
56
    end
57
    file.close()
58
    print("Function list saved to '" .. filename .. "'")
59
else
60
    print("Skipped saving.")
61
end
62