Pour nos fichiers TNS, le code est visible en clair (seule l'entête est compressée/cryptée).
Pour les fichiers TNS officiels, il n'y a pas encore de convertisseur automatique. On sait décrypter, mais ça reste du bricolage...
[TOPO]Langage Script TI OS 3.0 - enfin un langage API ?
-
critorAdmin
Niveau 19: CU (Créateur Universel)- Messages: 41494
- Images: 14632
- Inscription: 25 Oct 2008, 00:00
- Localisation: Montpellier
- Genre:
- Calculatrice(s):→ MyCalcs profile
- YouTube: critor3000
- Twitter/X: critor2000
- GitHub: critor
Re: [TOPO]Langage Script TI OS 3.0 - enfin un langage API ?
JayTe a écrit:Script uniquement (à renommer en .py) --> maketns.txt
Version compilée (inclut aussi le script, l'executable est dans le sous-dossier dist) -- maketns.zip
Bump : J'ai modifié quelque peu ton script de gestion (pas la partie conversion) pour gérer les multi-card (pages) et multi-widgets.
Les tests doivent surement être foireux et il doit planter dans pleins de cas, mais si on ne fait pas d'erreur, ça fonctionne.
- Code: Tout sélectionner
import os, zipfile, sys, math
if len(sys.argv) < 3:
print('Usage: \npython maketns.py \n\
<output_tns_file.tns> \n\
c=0 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend\n\
c=1 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend\n\
c=3 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend')
print('Note that different lua source files are simply concatenated.')
sys.exit(0)
outputFileName = sys.argv[1]
inputFileNames = sys.argv[2:len(sys.argv)]
#hex values of a blank tns file
blankTnsHexValues = [
'2a', '54', '49', '4d', '4c', '50', '30', '35',
'30', '30', '14', '00', '00', '00', '0d', '00',
'3c', '17', '8d', '3e', '73', '45', '68', '44',
'40', '01', '00', '00', '93', '02', '00', '00',
'0c', '00', '00', '00', '44', '6f', '63', '75',
'6d', '65', '6e', '74', '2e', '78', '6d', '6c',
'0f', 'ce', 'd8', 'd2', '81', '06', '86', '5b',
'62', '81', 'c2', 'a6', '21', 'a5', 'fd', '08',
'23', '0f', '92', 'ae', '38', '45', '2a', '05',
'66', 'bb', 'c7', 'df', '98', '87', '55', '13',
'61', '47', '75', '24', '66', 'f9', '71', '1f',
'cd', 'e5', 'b3', '41', '5d', '13', '33', '4e',
'72', '0e', '08', 'fb', '76', '87', 'e6', '1d',
'8f', '93', '18', '32', 'e7', '06', '92', '6a',
'58', 'f0', '77', '22', '09', 'ba', 'ca', '25',
'b3', '8e', '7b', '52', '98', 'c5', '54', '9a',
'5f', '8c', '34', '9e', '35', 'f5', '6b', '75',
'45', 'c7', '7a', '10', '8a', '5f', '6e', '0d',
'e6', '4a', '1e', '90', '92', 'ba', '1c', 'd1',
'96', 'b0', 'c1', '19', 'cd', '5c', '0d', '27',
'9b', '19', '2f', '58', '6f', '49', '14', '95',
'0d', 'f1', '3a', 'c8', '99', '82', '2e', 'a3',
'ad', '36', '9e', 'b7', '13', '28', 'aa', '9b',
'89', 'b5', '30', 'fc', '3f', 'd4', 'd2', '45',
'be', 'c4', '7f', '86', '87', '71', '25', '09',
'd1', 'ed', 'b3', 'd3', '92', '69', 'df', 'b5',
'94', '72', 'a6', '37', '58', '58', 'c4', 'd4',
'29', 'd1', 'ba', 'af', '84', '4a', '2e', 'cf',
'2e', '7b', 'fb', 'bd', '91', 'ac', '99', 'ba',
'a8', 'cc', 'c0', '95', '5b', '21', 'e4', '3d',
'58', 'fa', '8f', 'c4', '21', 'c7', '66', 'c5',
'7b', 'a7', '31', '9f', '70', '2d', '1e', 'ce',
'37', '8a', '13', 'e1', 'e8', '1e', '88', '67',
'11', '7c', '3e', '7d', '75', '52', 'bd', '9a',
'40', 'd7', 'af', '3d', 'a1', '10', '3a', 'eb',
'91', 'c8', '8d', '4a', '24', '9b', '38', '85',
'8f', '38', 'b5', '3c', 'b5', 'a3', 'fa', '1b',
'be', '4a', 'ca', '93', 'd7', '41', '69', '02',
'0d', 'ad', '30', '6d', 'ba', '08', '54', 'fc',
'13', 'e8', 'fa', 'eb', 'c0', 'fd', 'e8', 'ad',
'51', '1a', '4a', '89', '95', '3a', '27', 'd4',
'f2', 'cc', '40', '46', 'cd', 'c9', '8a', '14',
'd5', '83', 'df', '60', 'dc', 'ce', '06', '5e',
'9e', '2e', 'b1', 'd3', '54', '97', 'f7', '7b',
'ae', '6f', '51', '4f', '74', 'dc', '57', '6a',
'd4', '7f', '37', '2a', '49', 'ba', '86', '2a']
#xml code which should be placed before and after the lua code
xmlCodeProbHeader = '<?xml version="1.0" encoding="UTF-8" ?><prob xmlns="urn:TI.Problem" ver="1.0" pbname=""><sym></sym>'
xmlCodeCardHeader = '<card clay="<[FORMAT]>"><isDummyCard>0</isDummyCard><flag>0</flag>' #h1="10000" h2="10000" w1="10000" w2="10000"
xmlCodeWidgetHeader = '<wdgt xmlns:sc="urn:TI.ScriptApp" type="TI.ScriptApp" ver="1.0"><sc:mFlags>0</sc:mFlags><sc:value>-1</sc:value><sc:script>'
xmlCodeWidgetFooter = '</sc:script></wdgt>'
xmlCodeCardFooter = '</card>'
xmlCodeProbFooter = '</prob>'
convertedLua = xmlCodeProbHeader
numWidget = 0
cardType = 0
for inputFileName in inputFileNames:
if inputFileName.find("c=") != -1:
numWidget = 0
cardType = int(inputFileName.replace('c=', '')) or 0
convertedLua += xmlCodeCardHeader.replace('<[FORMAT]>', str(cardType))
elif inputFileName == "cend":
if numWidget < 4 and cardType >= math.pow(2, numWidget - 1) - 1 and cardType < math.pow(2, numWidget) - 1:
convertedLua += xmlCodeCardFooter
else:
print('Too many Widgets (' + str(numWidget) +') per Card or Invalid Card Type (' + str(cardType) + ') ! Exit.')
print('Valid Card Types for [1 widget : 0], [2 widgets : 1, 2], [3 widgets : 3, 4, 5, 6], [4 widgets : 7]')
sys.exit(0)
elif inputFileName == "w":
numWidget += 1
convertedLua += xmlCodeWidgetHeader
elif inputFileName == "wend":
convertedLua += xmlCodeWidgetFooter
else:
inputFile = open(inputFileName, 'rb')
#encoding special chars of each line in the lua code
for line in inputFile:
conv = line.replace('&', '&')
conv = conv.replace('"', '"')
conv = conv.replace('\'', ''')
conv = conv.replace('<', '<')
conv = conv.replace('>', '>')
convertedLua += conv
inputFile.close()
xmlCode = convertedLua + xmlCodeProbFooter
#compressing the generated xml code to temp.zip
tempZip = zipfile.ZipFile('./temp.zip', 'w', zipfile.ZIP_DEFLATED)
tempZip.writestr('Problem1.xml', xmlCode)
tempZip.close()
outputFile = open(outputFileName, 'wb')
#writing blank tns file
for s in blankTnsHexValues:
outputFile.write(chr(eval('0x' + s)))
#appending created zip file
zipFile = open('./temp.zip', 'rb')
outputFile.write(zipFile.read())
zipFile.close()
outputFile.close()
#deleting temp.zip
os.remove('./temp.zip')
Exemple :
Fichier 1.lua
- Code: Tout sélectionner
function on.paint(gc)
gc:setFont("sansserif", "b", 10)
gc:drawString("Widget 1", 0, 0, "top")
end
Fichier 2.lua
- Code: Tout sélectionner
function on.paint(gc)
gc:setFont("sansserif", "b", 10)
gc:drawString("Widget 2", 0, 0, "top")
end
Ligne de commande :
- Code: Tout sélectionner
python ./maketns.py test.tns c=1 w ./1.lua wend w ./2.lua wend cend c=2 w ./1.lua wend w ./2.lua wend cend
Résultat :
-
LevakAdmin
Niveau 14: CI (Calculateur de l'Infini)- Messages: 6414
- Images: 22
- Inscription: 27 Nov 2008, 00:00
- Localisation: 0x1AACC355
- Genre:
- Calculatrice(s):→ MyCalcs profile
- Classe: BAC+5: Epita (ING3)
Re: [TOPO]Langage Script TI OS 3.0 - enfin un langage API ?
Sympa ca
Si ça te chante et que tas un peu de temps, fais le aussi sur le LUAtoTNS.sh
Si ça te chante et que tas un peu de temps, fais le aussi sur le LUAtoTNS.sh
MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)-
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)- Messages: 14614
- Images: 1218
- Inscription: 01 Juin 2007, 00:00
- Localisation: France
- Genre:
- Calculatrice(s):→ MyCalcs profile
- Twitter/X: adriweb
- GitHub: adriweb
Re: [TOPO]Langage Script TI OS 3.0 - enfin un langage API ?
Adriweb a écrit:Sympa ca
Si ça te chante et que tas un peu de temps, fais le aussi sur le LUAtoTNS.sh
J'ai fait ça pour maketns car
- Il gère les fichiers multiples
- JayTe n'est plus là, sinon je lui aurais directement demandé avant de modifier son code.
Allez, mais la main à la pâte, c'est pas très compliqué la génération de XML
Sinon, j'ai modifié encore une fois le script pour qu'il gère les proportions d'écran :
- Code: Tout sélectionner
import os, zipfile, sys, math
if len(sys.argv) < 3:
print('Usage: \npython maketns.py \n\
<output_tns_file.tns> \n\
c=0#50#50 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend\n\
c=1#0#50 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend\n\
c=3#20#10 \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
w\n\
<input_lua_file_1.lua> ... <input_lua_file_n.lua>\n\
wend \n\
cend')
print('Note that different lua source files are simply concatenated.')
sys.exit(0)
outputFileName = sys.argv[1]
inputFileNames = sys.argv[2:len(sys.argv)]
#hex values of a blank tns file
blankTnsHexValues = [
'2a', '54', '49', '4d', '4c', '50', '30', '35',
'30', '30', '14', '00', '00', '00', '0d', '00',
'3c', '17', '8d', '3e', '73', '45', '68', '44',
'40', '01', '00', '00', '93', '02', '00', '00',
'0c', '00', '00', '00', '44', '6f', '63', '75',
'6d', '65', '6e', '74', '2e', '78', '6d', '6c',
'0f', 'ce', 'd8', 'd2', '81', '06', '86', '5b',
'62', '81', 'c2', 'a6', '21', 'a5', 'fd', '08',
'23', '0f', '92', 'ae', '38', '45', '2a', '05',
'66', 'bb', 'c7', 'df', '98', '87', '55', '13',
'61', '47', '75', '24', '66', 'f9', '71', '1f',
'cd', 'e5', 'b3', '41', '5d', '13', '33', '4e',
'72', '0e', '08', 'fb', '76', '87', 'e6', '1d',
'8f', '93', '18', '32', 'e7', '06', '92', '6a',
'58', 'f0', '77', '22', '09', 'ba', 'ca', '25',
'b3', '8e', '7b', '52', '98', 'c5', '54', '9a',
'5f', '8c', '34', '9e', '35', 'f5', '6b', '75',
'45', 'c7', '7a', '10', '8a', '5f', '6e', '0d',
'e6', '4a', '1e', '90', '92', 'ba', '1c', 'd1',
'96', 'b0', 'c1', '19', 'cd', '5c', '0d', '27',
'9b', '19', '2f', '58', '6f', '49', '14', '95',
'0d', 'f1', '3a', 'c8', '99', '82', '2e', 'a3',
'ad', '36', '9e', 'b7', '13', '28', 'aa', '9b',
'89', 'b5', '30', 'fc', '3f', 'd4', 'd2', '45',
'be', 'c4', '7f', '86', '87', '71', '25', '09',
'd1', 'ed', 'b3', 'd3', '92', '69', 'df', 'b5',
'94', '72', 'a6', '37', '58', '58', 'c4', 'd4',
'29', 'd1', 'ba', 'af', '84', '4a', '2e', 'cf',
'2e', '7b', 'fb', 'bd', '91', 'ac', '99', 'ba',
'a8', 'cc', 'c0', '95', '5b', '21', 'e4', '3d',
'58', 'fa', '8f', 'c4', '21', 'c7', '66', 'c5',
'7b', 'a7', '31', '9f', '70', '2d', '1e', 'ce',
'37', '8a', '13', 'e1', 'e8', '1e', '88', '67',
'11', '7c', '3e', '7d', '75', '52', 'bd', '9a',
'40', 'd7', 'af', '3d', 'a1', '10', '3a', 'eb',
'91', 'c8', '8d', '4a', '24', '9b', '38', '85',
'8f', '38', 'b5', '3c', 'b5', 'a3', 'fa', '1b',
'be', '4a', 'ca', '93', 'd7', '41', '69', '02',
'0d', 'ad', '30', '6d', 'ba', '08', '54', 'fc',
'13', 'e8', 'fa', 'eb', 'c0', 'fd', 'e8', 'ad',
'51', '1a', '4a', '89', '95', '3a', '27', 'd4',
'f2', 'cc', '40', '46', 'cd', 'c9', '8a', '14',
'd5', '83', 'df', '60', 'dc', 'ce', '06', '5e',
'9e', '2e', 'b1', 'd3', '54', '97', 'f7', '7b',
'ae', '6f', '51', '4f', '74', 'dc', '57', '6a',
'd4', '7f', '37', '2a', '49', 'ba', '86', '2a']
#xml code which should be placed before and after the lua code
xmlCodeProbHeader = '<?xml version="1.0" encoding="UTF-8" ?><prob xmlns="urn:TI.Problem" ver="1.0" pbname=""><sym></sym>'
xmlCodeCardHeader = '<card clay="<[FORMAT]>" w1="<[WIDTH]>" h1="<[HEIGHT]>" w2="1" h2="1"><isDummyCard>0</isDummyCard><flag>0</flag>'
xmlCodeWidgetHeader = '<wdgt xmlns:sc="urn:TI.ScriptApp" type="TI.ScriptApp" ver="1.0"><sc:mFlags>0</sc:mFlags><sc:value>-1</sc:value><sc:script>'
xmlCodeWidgetFooter = '</sc:script></wdgt>'
xmlCodeCardFooter = '</card>'
xmlCodeProbFooter = '</prob>'
convertedLua = xmlCodeProbHeader
numWidget = 0
cardType = 0
for inputFileName in inputFileNames:
if inputFileName.find("c=") != -1:
numWidget = 0
explode = inputFileName.replace('c=', '').split('#')
cardType = int(explode[0]) or 0
if len(explode) > 1:
width = int(explode[1]) * 100 + 1
if len(explode) > 2:
height = int(explode[2]) * 100 + 1
else:
height = 1
else:
width = 0
height = 0
convertedLua += xmlCodeCardHeader.replace('<[FORMAT]>', str(cardType))
convertedLua = convertedLua.replace('<[WIDTH]>', str(width))
convertedLua = convertedLua.replace('<[HEIGHT]>', str(height))
elif inputFileName == "cend":
if numWidget < 4 and cardType >= math.pow(2, numWidget - 1) - 1 and cardType < math.pow(2, numWidget) - 1:
convertedLua += xmlCodeCardFooter
else:
print('Too many Widgets (' + str(numWidget) +') per Card or Invalid Card Type (' + str(cardType) + ') ! Exit.')
print('Valid Card Types for [1 widget : 0], [2 widgets : 1, 2], [3 widgets : 3, 4, 5, 6], [4 widgets : 7]')
sys.exit(0)
elif inputFileName == "w":
numWidget += 1
convertedLua += xmlCodeWidgetHeader
elif inputFileName == "wend":
convertedLua += xmlCodeWidgetFooter
else:
inputFile = open(inputFileName, 'rb')
#encoding special chars of each line in the lua code
for line in inputFile:
conv = line.replace('&', '&')
conv = conv.replace('"', '"')
conv = conv.replace('\'', ''')
conv = conv.replace('<', '<')
conv = conv.replace('>', '>')
convertedLua += conv
inputFile.close()
xmlCode = convertedLua + xmlCodeProbFooter
#compressing the generated xml code to temp.zip
tempZip = zipfile.ZipFile('./temp.zip', 'w', zipfile.ZIP_DEFLATED)
tempZip.writestr('Problem1.xml', xmlCode)
tempZip.close()
outputFile = open(outputFileName, 'wb')
#writing blank tns file
for s in blankTnsHexValues:
outputFile.write(chr(eval('0x' + s)))
#appending created zip file
zipFile = open('./temp.zip', 'rb')
outputFile.write(zipFile.read())
zipFile.close()
outputFile.close()
#deleting temp.zip
os.remove('./temp.zip')
Ligne de commande
- Code: Tout sélectionner
python ./maketns.py test.tns c=1#30 w ./1.lua wend w ./2.lua wend cend c=2#0#20 w ./1.lua wend w ./2.lua wend cend
Résultat :
-
LevakAdmin
Niveau 14: CI (Calculateur de l'Infini)- Messages: 6414
- Images: 22
- Inscription: 27 Nov 2008, 00:00
- Localisation: 0x1AACC355
- Genre:
- Calculatrice(s):→ MyCalcs profile
- Classe: BAC+5: Epita (ING3)
Re: [TOPO]Langage Script TI OS 3.0 - enfin un langage API ?
Superbe !
Enfin bon moi je ne me sers pratiquement que d'OCLua, mais ça doit être utile à pas mal de gens.
(Et puis OCLua pour ton Make3D, ça doit pas être possible )
Enfin bon moi je ne me sers pratiquement que d'OCLua, mais ça doit être utile à pas mal de gens.
(Et puis OCLua pour ton Make3D, ça doit pas être possible )
Mes programmes en Lua pour TI-Nspire : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField
-
ChockostaPremium
Niveau 10: GR (Guide de Référence)- Messages: 213
- Inscription: 24 Fév 2011, 00:00
- Genre:
- Calculatrice(s):→ MyCalcs profile
- Classe: Math sup
Qui est en ligne
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 3 invités