oblerion / ZeroBrane-Studio-with-TIC-80

ZeroBrane Studio autocomplete and interpreter for TIC-80
GNU General Public License v3.0
1 stars 1 forks source link

add support for multi file projects #8

Open atesin opened 2 months ago

atesin commented 2 months ago

you read this discussion in tic80 issues page: https://github.com/nesbox/TIC-80/issues/2668 ... i better keep analisys there and move technical questions here

i have some ideas on how to implement this, i hope they were not so hard, maybe the most practical woule be to let the package do all the work for us everytime, merging project files in a temp thus killing the need for require()'s also... something like:

but you need some way to specify project cart name before: maybe right click on on project > set cart name, or menu project > properties > esit cart name, or whatever (i dont know how, i a not a plugin/package developer nor have experience with zbs)

atesin commented 2 months ago

could you please teach me how to submit pull requests (have to fork before?)?? ... i have some ideas, i want you to code them and show you, and if you like them merge them

my email is like my username, but in gmail

oblerion commented 2 months ago

could you please teach me how to submit pull requests (have to fork before?)?? ... i have some ideas, i want you to code them and show you, and if you like them merge them

Yes, you need to make a fork (your copy of the project), edit it and make a pull request when you agree. Your pull request is updated at the same time as your fork edit. And don't worry, you need approval before merging.

oblerion commented 2 months ago

You can do cat lib.lua >> tmp_cart.lua in lua

function cat(lib, tmp_cart)

end

I will do parsing for use your function each time it see:

--import lib.lua

in game lua cart.

And use

--cart tmp_cart.lua

for set cart output name.

atesin commented 2 months ago

for this to work i think we need some info before:

also i suggest to change config variable names from xxx.tic80 to tic80.xxxx instead, going from general to particular, this way is more easier to group/find more future tic80 related variables

atesin commented 2 months ago

this can be done even with an ms-dos batch!

while working a tic80 project with zbs, in parallel, supposing we are in <tic80-fs-folder>\merge-test subfolder:

type > mergedlua.tmp
type *.lua >> mergedlua.tmp
if exist mycart.tic (
  F:\Games\tic80\tic80.exe mycart.tic --cmd="import code merge-test/mergedlua.tmp & save & run"
) else (
  F:\Games\tic80\tic80.exe --cmd="new lua & import code merge-test/mergedlua.tmp & save merge-test/mycart & run"
)
del mergedlua.tmp

i am using this and it works flawlesly... question is, how to convert this batch to a zbs lua package, to make it easy for everyone

we must know previously:

limitations:

oblerion commented 2 months ago

this can be done even with an ms-dos batch! i am using this and it works flawlesly... question is, how to convert this batch to a zbs lua package, to make it easy for everyone

Batch work only for window, you need this functions for translate in lua.

function string.cmp(str,str2) -- string is egal
  if str:len() ~= str2:len() then
    return false
  end
  for ic=1,#str do
    if str:byte(ic) ~= str2:byte(ic) then
      return false
    end
  end
  return true
end
function getos()
  local BinaryFormat = package.cpath:match("%p[\\|/]?%p(%a+)")
  if BinaryFormat == "dll" then
    return "Windows"
  elseif BinaryFormat == "so" then
    return "Linux"
  elseif BinaryFormat == "dylib" then
    return "MacOS"
  end
  BinaryFormat = nil
  return ""
end
function scandir(directory) -- get array of file name
  local i, t, popen = 0, {}, io.popen
  local pfile 
  if string.cmp(getos(),"Linux")==true or string.cmp(getos(),"MacOS")==true then 
    pfile = popen('ls -a "'..directory..'"')
  else
    pfile = popen('dir '..directory)
  end
  for filename in pfile:lines() do
    i = i + 1
    t[i] = filename
  end
  pfile:close()
  return t
end
function is_fileext(path,ext) -- check file extension
  local extsize = ext:len()-1
  local extstring = path:sub(path:len()-extsize,path:len())
  if string.cmp(extstring,ext)==true then
    return true
  end
  return false
end
function is_dir(path)
  local f = io.open(path, "r")
  local ok, err, code = f:read(1)
  f:close()
  return code == 21
end
function is_file(path)
  local f = io.open(path, "r")
  if f~=nil then
    f:close()
    return true
  end
  return false
end
function create_file(path)
  local fic = io.open(path,"w")
  fic:write("")
  fic:close()
end
function del_file(path)
  if not is_dir(path)==true then
    if string.cmp(getos(),"Linux")==true or string.cmp(getos(),"MacOS")==true then 
      popen('rm '..path)
    else
      popen('del '..path)
    end
  end
end
function cat_file(src,out)
  if is_file(src)==true and is_file(out)==true then
    popen('cat '..src..' >> '..out)
  end
end

an example

local d = scandir('.') -- array of file name
for i=1,#d do
  if is_fileext(d[i],'.lua')==true then
-- print only lua file
    print(d[i])
  end
end

note

oblerion commented 2 months ago

all files must/will be in the same folder (luas and tic) neverless they are opened or not (works with saved version)

it need to define tic80.libpath in config file

9

oblerion commented 2 months ago

also i suggest to change config variable names from xxx.tic80 to tic80.xxxx instead, going from general to particular, this way is more easier to group/find more future tic80 related variables

9

atesin commented 2 months ago

i have a general idea on how this new feature could work, but i am boiling my head since many days in front of my editor trying to figure out how to do this (i suck at programming, augmented with an awful documentation xD )... maybe you know how to do it:

what do you think?.. do you think is possible?, do you have an idea on how to achieve these?... do you like them ? :)

atesin commented 2 months ago

some resources i could have found: official ZBS plugin documentation (from homepage) = https://studio.zerobrane.com/doc-plugin , there are some info like:

atesin commented 1 month ago

some simplifications:

i honestly tried to modify the plugin by myself, but i bumped with lack of documentation... for example there is an ID() function that i have no idea what it does, also this function seems to accepts constant-looking parameters that are specified nowhere... i searched for definitions in zbs code with dngrep and in zbs and wxwidgets documentation but i found nothing related, i am very frustrated with this :(

atesin commented 1 month ago

look at this ... maybe we can use some of the tools mentioned here, some are written in lua:

https://github.com/nesbox/TIC-80/issues/2426#issuecomment-2397252479