Skip to content

Commit

Permalink
fix path and and add interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
oblerion authored Sep 3, 2024
1 parent 888f6f1 commit 83e1236
Showing 1 changed file with 66 additions and 14 deletions.
80 changes: 66 additions & 14 deletions packages/tic80.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local win = ide.osname == "Windows"
local mac = ide.osname == "Macintosh"
local api = {}
local interpreter = {}
local name = 'TIC-80'
--local api = {}
--local interpreter = {}
local name = "TIC-80"

-- file: interpreters/tic80.lua
--[[--
Expand All @@ -12,13 +12,24 @@ local name = 'TIC-80'
Original writer : librorumque 2019
Update and opti : oblerion 2024
--]]--
interpreter = {
name=name,
local function pathremover(path)
if type(path)=="string" then
local charfnd = string.byte("/")
for c=path:len(),1,-1 do
if path:byte(c) == charfnd then
return path:sub(c+1,path:len())
end
end
end
return path
end
local interpreter_debug = {
name=name.."_LUA",
description="TIC-80 is a tiny computer which you can use to make, play, and share tiny games.",
api={name},
luaversion="5.3",
frun=function(self,wfilename)
local luapath = wfilename:GetFullPath()
local luapath = pathremover(wfilename:GetFullPath())
local tic80 = nil--= locateexe()
local cart = luapath:sub(1,luapath:len()-4)..".tic"
local code = luapath
Expand All @@ -45,22 +56,63 @@ interpreter = {
ide:Print("No source file specified. The code from the cart will run. To use a source file open it in the editor, or add `-code /path/to/file.lua` in `Project > Command Line Parameters...`")
end

local cmd = string.format(tic80.." --cmd="..'"'.."load "..cart.."& import code %s"..'"',code)
local cmd = string.format("%s --skip --cmd=%sload %s & run %s",tic80,'"',code,'"')
--string.format("%s --skip --cmd=%sload %s & import code %s & run %s",tic80,'"',cart,code,'"')
return CommandLineRun(cmd,self:fworkdir(wfilename),true,true,nil,nil,nil)
end,
skipcompile = true,
hasdebugger=false,
scratchextloop = false,
takeparameters = true
}
local interpreter_release = {
name=name.."_TIC",
description="TIC-80 is a tiny computer which you can use to make, play, and share tiny games.",
api={name},
luaversion="5.3",
frun=function(self,wfilename)
local luapath = pathremover(wfilename:GetFullPath())
local tic80 = nil--= locateexe()
local cart = luapath:sub(1,luapath:len()-4)..".tic"
local code = luapath
-- set or default tic80 path
if ide.config.path.tic80~=nil then
tic80 = ide.config.path.tic80
elseif win then
tic80 = "C:/Program Files (x86)/Tic80/tic80.exe"
elseif mac then
-- need edit by mac user
else -- linux user
tic80 = "/usr/bin/tic80"
end

if not tic80 then
ide:Print("TIC-80 executable not found. Please add `path.tic80` in the config file (`Edit > Preferences`)")
end

if not cart then
ide:Print("Using a default cart. To use an existing cart put it in the same dir as the source file, or add `/path/to/file.tic` in `Project > Command Line Parameters...`")
end

if not code then
ide:Print("No source file specified. The code from the cart will run. To use a source file open it in the editor, or add `-code /path/to/file.lua` in `Project > Command Line Parameters...`")
end

local cmd = string.format("%s --skip --cmd=%sload %s & save %s & load %s & run %s",tic80,'"',code,cart,cart,'"')
return CommandLineRun(cmd,self:fworkdir(wfilename),true,true,nil,nil,nil)
end,
skipcompile = true,
hasdebugger=false,
scratchextloop = false,
takeparameters = true
}
--[[--
TIC-80 API for ZBStudio
Original writer : librorumque 2019
Update : oblerion 2024
--]]--

api = {
local api = {
BDR = {
type = "function",
description = [[The BDR callback allows you to execute code between the rendering of each scan line\nline = line number]],
Expand Down Expand Up @@ -406,22 +458,22 @@ for item, def in pairs(lua) do
api[item] = def
end
end

-- package TIC-80
return {
name = name,
description = "Implements integration with TIC80.",
author = "librorumque, oblerion, atesin",
version = 0.01,

version = 0.1,
onRegister = function(self)
ide:AddInterpreter(name, interpreter)
ide:AddInterpreter(interpreter_debug.name, interpreter_debug)
ide:AddInterpreter(interpreter_release.name, interpreter_release)
ide:AddAPI("lua", name, api)
--ide:AddSpec(name, spec)
end,
onUnRegister = function(self)
ide:RemoveInterpreter(name)
ide:RemoveInterpreter(interpreter_debug.name, interpreter_debug)
ide:RemoveInterpreter(interpreter_release.name, interpreter_release)
ide:RemoveAPI("lua", name)
--ide:RemoveSpec(name)
end,
}

0 comments on commit 83e1236

Please sign in to comment.