<commit_before>--
-- colony-node.lua
-- Initializes Node-specific global APIs, and the event loop.
--

local bit = require('bit32')
local tm = require('tm')
local http_parser = require('http_parser')

-- locals

local js_arr = colony.js_arr
local js_obj = colony.js_obj
local js_new = colony.js_new
local js_tostring = colony.js_tostring
local js_instanceof = colony.js_instanceof
local js_void = colony.js_void
local js_pairs = colony.js_pairs
local js_typeof = colony.js_typeof
local js_arguments = colony.js_arguments
local js_break = colony.js_break
local js_cont = colony.js_cont
local js_seq = colony.js_seq
local js_in = colony.js_in
local js_setter_index = colony.js_setter_index
local js_getter_index = colony.js_getter_index
local js_proto_get = colony.js_proto_get
local js_func_proxy = colony.js_func_proxy

local obj_proto = colony.obj_proto
local num_proto = colony.num_proto
local func_proto = colony.func_proto
local str_proto = colony.str_proto
local arr_proto = colony.arr_proto
local regex_proto = colony.regex_proto

local global = colony.global

--[[
--|| Events
--]]

_G._colony_emit = function (type, data)
  -- TODO remove "type" variable, is useless
  colony.global.process:emit('raw-message', global:Buffer(data))
end

--[[
--|| Lua Timers
--]]

function wrap_timer_cb(fn, ...)
  -- If extra args were passed, encapsulate them in a closure
  if select("#", ...) then
    local orig_fn = fn
    local args = table.pack(...)
    fn = function()
      orig_fn(global, unpack(args))
    end
  end
  return fn
end

global.setTimeout = function (this, fn, timeout, ...)
  return tm.set_raw_timeout(timeout, false, wrap_timer_cb(fn, ...))
end

global.setInterval = function (this, fn, timeout, ...)
  if timeout < 1 then
    -- Clamp minimum repeat interval, as the C repeat field cannot be 0
    timeout = 1
  end
  return tm.set_raw_timeout(timeout, true, wrap_timer_cb(fn, ...))
end<commit_msg>Emits IPC events based on input<commit_after>--
-- colony-node.lua
-- Initializes Node-specific global APIs, and the event loop.
--

local bit = require('bit32')
local tm = require('tm')
local http_parser = require('http_parser')

-- locals

local js_arr = colony.js_arr
local js_obj = colony.js_obj
local js_new = colony.js_new
local js_tostring = colony.js_tostring
local js_instanceof = colony.js_instanceof
local js_void = colony.js_void
local js_pairs = colony.js_pairs
local js_typeof = colony.js_typeof
local js_arguments = colony.js_arguments
local js_break = colony.js_break
local js_cont = colony.js_cont
local js_seq = colony.js_seq
local js_in = colony.js_in
local js_setter_index = colony.js_setter_index
local js_getter_index = colony.js_getter_index
local js_proto_get = colony.js_proto_get
local js_func_proxy = colony.js_func_proxy

local obj_proto = colony.obj_proto
local num_proto = colony.num_proto
local func_proto = colony.func_proto
local str_proto = colony.str_proto
local arr_proto = colony.arr_proto
local regex_proto = colony.regex_proto

local global = colony.global

--[[
--|| Events
--]]

_G._colony_emit = function (type, data)
  colony.global.process:emit(type, data)
end

--[[
--|| Lua Timers
--]]

function wrap_timer_cb(fn, ...)
  -- If extra args were passed, encapsulate them in a closure
  if select("#", ...) then
    local orig_fn = fn
    local args = table.pack(...)
    fn = function()
      orig_fn(global, unpack(args))
    end
  end
  return fn
end

global.setTimeout = function (this, fn, timeout, ...)
  return tm.set_raw_timeout(timeout, false, wrap_timer_cb(fn, ...))
end

global.setInterval = function (this, fn, timeout, ...)
  if timeout < 1 then
    -- Clamp minimum repeat interval, as the C repeat field cannot be 0
    timeout = 1
  end
  return tm.set_raw_timeout(timeout, true, wrap_timer_cb(fn, ...))
end
{'fraction_non_alphanumeric': 0.10711451996826236, 'fraction_numerical': 0.0026448029621793175, 'mean_word_length': 4.05614973262032, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2928248', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1265, 'n_words': 354}