<commit_before>-- Lua functions
local assert = assert(assert, "Функция 'assert' не найдена.")
local error = assert(error, "Функция 'error' не найдена.")
local string = assert(string, "Taблица 'string' не найдена.")
local pcall = assert(pcall, "Функция 'pcall' не найдена.")
local pairs = assert(pairs, "Функция 'pairs' не найдена.")
local ipairs = assert(ipairs, "Функция 'ipairs' не найдена.")
local tostring = assert(tostring, "Функция 'tostring' не найдена.")
local loadstring = assert(loadstring, "Функция 'loadstring' не найдена.")
local table = assert(table, "Таблица 'table' не найдена.")
local bit = assert(bit, "Таблица 'bit' не найдена.")
local unpack = assert(unpack, "Функция 'unpack' не найдена.")

-- Utility modules and functions
local utils = require("utils.utils")
local uuid = require("utils.uuid")

-----
-- The DataSources in-memory storage. 
-- Warning: the storage may cause memory leaks if the datasources that aren't needed anymore have not been explicitly closed by the clients, 
-- because the datasources' objects would never be eligible for garbage collection (whereas in a local script they become so as soon as the script exits the main function).
local datasources = {}
local function get_datasource (datasource_uid)
  return assert(datasources[datasource_uid], string.format("DataSource c uuid='%s' не найден.", datasource_uid))
end

-----

local function requireNonNil (x)
  
  if x == nil then error("Целевая QLua-функция возвратила nil.") end
  return x 
end

local function to_string_string_table (t)
  
  local result = {}
  for k, v in pairs(t) do
    result[utils.Cp1251ToUtf8(tostring(k))] = utils.Cp1251ToUtf8(tostring(v))
  end
  
  return result
end

-----

local module = {}

-- TODO: test
module["isConnected"] = function ()
  return requireNonNil(_G.isConnected())
end

-- TODO: test
module["getScriptPath"] = function ()
  return requireNonNil(_G.getScriptPath())
end

-- TODO: test
module["getInfoParam"] = function (args)
  return utils.Cp1251ToUtf8(requireNonNil(_G.getInfoParam(args.param_name)))
end

module["message"] = function (args)
  -- returns 1 or nil
  return _G.message(utils.Utf8ToCp1251(args.message), args.icon_type)
end

-- TODO: test
module["sleep"] = function (args) 
  -- returns nil in case of error
  return _G.sleep(args.time)
end

-- TODO: test
module["getWorkingFolder"] = function ()
  return requireNonNil(_G.getWorkingFolder())
end

-- TODO: test
module["PrintDbgStr"] = function (args) 
  _G.PrintDbgStr(args.s)
end

-- TODO: test
module["os.sysdate"] = function () 
  return os.sysdate()
end

-- TODO: test
module["getItem"] = function (args) 
  
  -- returns nil in case of error
  local result = _G.getItem(args.table_name, args.index)
  return result and to_string_string_table(result) or nil
end

-- TODO: test
module["getOrderByNumber"] = function (args) 
  
  local order, indx = _G.getOrderByNumber(args.class_code, args.order_id)
  
  -- post-processing: stringify non-string non-mandatory fields, assert the precence of mandatory fields
  if order then
    assert(order.order_num, "Таблица 'order' не содержит обязательного поля 'order_num'.")
    assert(order.flags, "Таблица 'order' не содержит обязательного поля 'flags'.")
    order.brokerref = utils.Cp1251ToUtf8(order.brokerref)
    order.userid = utils.Cp1251ToUtf8(order.userid)
    order.firmid = utils.Cp1251ToUtf8(order.firmid)
    order.account = utils.Cp1251ToUtf8(order.account)<commit_msg>Added a workaround for #22.<commit_after>-- Lua functions
local assert = assert(assert, "Функция 'assert' не найдена.")
local error = assert(error, "Функция 'error' не найдена.")
local string = assert(string, "Taблица 'string' не найдена.")
local pcall = assert(pcall, "Функция 'pcall' не найдена.")
local pairs = assert(pairs, "Функция 'pairs' не найдена.")
local ipairs = assert(ipairs, "Функция 'ipairs' не найдена.")
local tostring = assert(tostring, "Функция 'tostring' не найдена.")
local loadstring = assert(loadstring, "Функция 'loadstring' не найдена.")
local table = assert(table, "Таблица 'table' не найдена.")
local bit = assert(bit, "Таблица 'bit' не найдена.")
local unpack = assert(unpack, "Функция 'unpack' не найдена.")

-- Utility modules and functions
local utils = require("utils.utils")
local uuid = require("utils.uuid")

-----
-- The DataSources in-memory storage. 
-- Warning: the storage may cause memory leaks if the datasources that aren't needed anymore have not been explicitly closed by the clients, 
-- because the datasources' objects would never be eligible for garbage collection (whereas in a local script they become so as soon as the script exits the main function).
local datasources = {}
local function get_datasource (datasource_uid)
  return assert(datasources[datasource_uid], string.format("DataSource c uuid='%s' не найден.", datasource_uid))
end

-----

local function requireNonNil (x)
  
  if x == nil then error("Целевая QLua-функция возвратила nil.") end
  return x 
end

local function to_string_string_table (t)
  
  local result = {}
  for k, v in pairs(t) do
    result[utils.Cp1251ToUtf8(tostring(k))] = utils.Cp1251ToUtf8(tostring(v))
  end
  
  return result
end

-----

local module = {}

-- TODO: test
module["isConnected"] = function ()
  return requireNonNil(_G.isConnected())
end

-- TODO: test
module["getScriptPath"] = function ()
  return requireNonNil(_G.getScriptPath())
end

-- TODO: test
module["getInfoParam"] = function (args)
  return utils.Cp1251ToUtf8(requireNonNil(_G.getInfoParam(args.param_name)))
end

module["message"] = function (args)
  -- returns 1 or nil
  return _G.message(utils.Utf8ToCp1251(args.message), args.icon_type)
end

-- TODO: test
module["sleep"] = function (args) 
  -- returns nil in case of error
  return _G.sleep(args.time)
end

-- TODO: test
module["getWorkingFolder"] = function ()
  return requireNonNil(_G.getWorkingFolder())
end

-- TODO: test
module["PrintDbgStr"] = function (args) 
  _G.PrintDbgStr(args.s)
end

-- TODO: test
module["os.sysdate"] = function () 
  return os.sysdate()
end

-- TODO: test
module["getItem"] = function (args) 
  
  -- returns nil in case of error
  local result = _G.getItem(args.table_name, args.index)
  if type(result) ~= 'table' then
    result = {singular_result = tostring(result)}
  end
  return result and to_string_string_table(result) or nil
end

-- TODO: test
module["getOrderByNumber"] = function (args) 
  
  local order, indx = _G.getOrderByNumber(args.class_code, args.order_id)
  
  -- post-processing: stringify non-string non-mandatory fields, assert the precence of mandatory fields
  if order then
    assert(order.order_num, "Таблица 'order' не содержит обязательного поля 'order_num'.")
    assert(order.flags, "Таблица 'order' не содержит обязательного поля 'flags'.")
    order.brokerref = utils.Cp1251ToUtf8(order.brokerref)
    order.userid = utils.Cp1251ToUtf8(order.userid)
    order.firmid = utils.Cp1251ToUtf8(order.firmid)
    order.account = utils.Cp1251ToUtf8(order.account)
{'fraction_non_alphanumeric': 0.12253077583738907, 'fraction_numerical': 0.012024048096192385, 'mean_word_length': 4.4886095836606446, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5257278', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2472, 'n_words': 677}