<commit_before>--Corouting Registry: this file is responsible for providing LIKO12 it's api--
local coreg = {reg={},stack={}}

local sandbox = require("Engine.sandbox")

--Returns the current active coroutine if exists
function coreg:getCoroutine()
  return self.co, self.coglob
end

--Sets the current active coroutine
function coreg:setCoroutine(co,glob)
  self.co  = co or self.co
  self.coglob = glob or self.coglob
  return self
end

--Push the current coroutine to the coroutine stack,
-- and set the current coroutine to nil
function coreg:pushCoroutine()
  table.insert(self.stack,self.co)
  self.co = nil
end

--Pop a coroutine from the coroutine stack.
function coreg:popCoroutine()
  if #self.stack < 1 then return error("No coroutines in the stack") end
  self.co = self.stack[1]
  for i=2,#self.stack do
    self.stack[i-1] = self.stack[i]
  end
  self.stack[#self.stack] = nil
end

--Call a function with the coroutine system plugged (A sub-coroutine)
function coreg:subCoroutine(func)
  self:pushCoroutine()
  self.co = coroutine.create(func)
end

--Resumes the current active coroutine if exists.
function coreg:resumeCoroutine(...)
  local lastargs = {...}
  while true do
    if not self.co or coroutine.status(self.co) == "dead" then return end
    local args = {coroutine.resume(self.co,unpack(lastargs))}
    if not args[1] then error(args[2]) end --Should have a better error handelling
    if coroutine.status(self.co) == "dead" and #self.stack >= 1 then --Hook system
      lastargs = args
      self:popCoroutine()
    else
      if not args[2] then self.os = nil; return end
      args = {self:trigger(select(2,unpack(args)))}
      if not args[1] then lastargs = args
      elseif not(type(args[1]) == "number" and args[1] == 2) then
        lastargs = args
      else break end
    end<commit_msg>Bugfix subCoroutine<commit_after>--Corouting Registry: this file is responsible for providing LIKO12 it's api--
local coreg = {reg={},stack={}}

local sandbox = require("Engine.sandbox")

--Returns the current active coroutine if exists
function coreg:getCoroutine()
  return self.co, self.coglob
end

--Sets the current active coroutine
function coreg:setCoroutine(co,glob)
  self.co  = co or self.co
  self.coglob = glob or self.coglob
  return self
end

--Push the current coroutine to the coroutine stack,
-- and set the current coroutine to nil
function coreg:pushCoroutine()
  table.insert(self.stack,self.co)
  self.co = nil
end

--Pop a coroutine from the coroutine stack.
function coreg:popCoroutine()
  if #self.stack < 1 then return error("No coroutines in the stack") end
  self.co = self.stack[1]
  for i=2,#self.stack do
    self.stack[i-1] = self.stack[i]
  end
  self.stack[#self.stack] = nil
end

--Call a function with the coroutine system plugged (A sub-coroutine)
function coreg:subCoroutine(func)
  self:pushCoroutine()
  self.co = coroutine.create(func)
end

--Resumes the current active coroutine if exists.
function coreg:resumeCoroutine(...)
  local lastargs = {...}
  while true do
    if not self.co or coroutine.status(self.co) == "dead" then return end
    local args = {coroutine.resume(self.co,unpack(lastargs))}
    if not args[1] then error(args[2]) end --Should have a better error handelling
    if coroutine.status(self.co) == "dead" and #self.stack >= 1 then --Hook system
      lastargs = {select(2,unpack(args))}
      self:popCoroutine()
    else
      if not args[2] then self.os = nil; return end
      args = {self:trigger(select(2,unpack(args)))}
      if not args[1] then lastargs = args
      elseif not(type(args[1]) == "number" and args[1] == 2) then
        lastargs = args
      else break end
    end
{'fraction_non_alphanumeric': 0.1145266594124048, 'fraction_numerical': 0.008433079434167573, 'mean_word_length': 3.619346733668342, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1017816', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1237, 'n_words': 392}