diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f14b74d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +/.vs diff --git a/target/fastweb.lua b/target/fastweb.lua new file mode 100644 index 0000000..f3df6ff --- /dev/null +++ b/target/fastweb.lua @@ -0,0 +1,106 @@ +-- fastweb.lua +local fastweb = {} +--[[ + 生成软件唯一GUID + @return 返回唯一GUID字符串 +]] +function fastweb.make_software_guid() + return fw_make_software_guid() +end + +--[[ + 接管打印 + @param args 可变参数 +]] +function fastweb.print(...) + fw_print(...) +end + +--[[ + 置全局指针 + @param name 名称 + @param ptr 指针 + @return 是否成功设置 +]] +function fastweb.set_ptr(name, ptr) + return fw_set_ptr(name, ptr) +end + +--[[ + 置全局文本 + @param name 名称 + @param value 文本值 +]] +function fastweb.set_str(name, value) + fw_set_str(name, value) +end + +--[[ + 取全局文本 + @param name 名称 + @return 返回全局文本值 +]] +function fastweb.get_str(name) + return fw_get_str(name) +end + +--[[ + 抛出异常 + @param msg 异常信息 +]] +function fastweb.throw_string(msg) + fw_throw_string(msg) +end + +--[[ + 网站目录 + @return 返回网站目录路径 +]] +function fastweb.website_dir() + return fw_website_dir() +end + +--[[ + 取当前毫秒时间戳 +]] +function fastweb.now_msec() + return fw_now_msec() +end + +--[[ + 取当前秒时间戳 +]] +function fastweb.now_sec() + return fw_now_sec() +end + +--[[ + 创建LUA虚拟机环境 + param lua_filepath LUA路径 +]] +function fastweb.create_env(lua_filepath) + return fw_create_env(lua_filepath) +end + +--[[ + 睡眠 +]] +function fastweb.sleep_msec(msec) + fw_sleep_msec(msec) +end + +--[[ + 取当前毫秒时间戳 +]] +function fastweb.now_msec() + return fw_now_msec() +end + +--[[ + 转INT +]] +function fastweb.toint(obj) + return fw_toint(obj) +end + +return fastweb diff --git a/target/fastweb/auto_lock.lua b/target/fastweb/auto_lock.lua new file mode 100644 index 0000000..64f7375 --- /dev/null +++ b/target/fastweb/auto_lock.lua @@ -0,0 +1,11 @@ + +local M = {} +M.__index = M + +function M.new(mutex) + local instance = setmetatable({}, M) + instance.module = fw_auto_lock.new(mutex) + return instance +end + +return M diff --git a/target/fastweb/codec.lua b/target/fastweb/codec.lua new file mode 100644 index 0000000..e41592a --- /dev/null +++ b/target/fastweb/codec.lua @@ -0,0 +1,84 @@ +local M = {} + + +--[[ +FUNCTION: URL解码 +--]] +function M.url_de(value) + return fw_codec.url_de(value) +end + +--[[ +FUNCTION: URL编码 +--]] +function M.url_en(value) + return fw_codec.url_en(value) +end + +--[[ +FUNCTION: GBK转UTF8 +--]] +function M.to_utf8(value) + return fw_codec.to_utf8(value) +end + +--[[ +FUNCTION: UTF8转GBK +--]] +function M.to_gbk(value) + return fw_codec.to_gbk(value) +end + +--[[ +FUNCTION: MD5校验 +--]] +function M.md5(value) + return fw_codec.md5(value) +end + +--[[ +FUNCTION: SHA1校验转十六进制 +--]] +function M.sha1(value) + return fw_codec.sha1(value) +end + +--[[ +FUNCTION: SHA256校验转十六进制 +--]] +function M.sha256(value) + return fw_codec.sha256(value) +end + +--[[ +FUNCTION: HMAC_SHA256校验转十六进制 +--]] +function M.hmac_sha256(key,value) + return fw_codec.hmac_sha256(key,value) +end + +--[[ +FUNCTION: AES加密 +@param: key +@param: value +@param: v(aes-256\aes-192\aes-128) +@param: m(cbc\ebc) +--]] +function M.aes_en(key,value,v,m) + return fw_codec.aes_encode(value,key,v,m) +end + + +--[[ +FUNCTION: AES解密 +@param: key +@param: value +@param: v(aes-256\aes-192\aes-128) +@param: m(cbc\ebc) +--]] +function M.aes_de(key,value,v,m) + return fw_codec.aes_decode(value,key,v,m) +end + + +return M \ No newline at end of file diff --git a/target/fastweb/ini.lua b/target/fastweb/ini.lua new file mode 100644 index 0000000..b8189d3 --- /dev/null +++ b/target/fastweb/ini.lua @@ -0,0 +1,102 @@ +local ini = {} +ini.__index = ini + +--[[ + 打开一个文件 + @param filepath 文件路径 + @return 是否成功打开文件 +]] +function ini:open(filepath) + return self.module:open(filepath) +end + +--[[ + 关闭当前打开的文件 +]] +function ini:close() + self.module:close() +end + +--[[ + 读取一个键值 + @param node 节点名称 + @param key 键名称 + @param default_value 默认值 + @return 返回键值,如果不存在则返回默认值 +]] +function ini:read(node, key, default_value) + return self.module:read(node, key, default_value) +end + +--[[ + 写入一个键值 + @param node 节点名称 + @param key 键名称 + @param value 值 + @return 是否成功写入 +]] +function ini:write(node, key, value) + return self.module:write(node, key, value) +end + +--[[ + 删除一个键 + @param node 节点名称 + @param key 键名称 + @return 是否成功删除 +]] +function ini:del(node, key) + return self.module:del(node, key) +end + +--[[ + 获取所有节点 + @return 返回所有节点的表 +]] +function ini:nodes() + return self.module:nodes() +end + +--[[ + 获取指定节点的所有键 + @param node 节点名称 + @return 返回该节点下所有键的表 +]] +function ini:keys(node) + return self.module:keys(node) +end + +--[[ + 检查键是否存在 + @param node 节点名称 + @param key 键名称 + @return 键是否存在 +]] +function ini:exist_key(node, key) + return self.module:exist_key(node, key) +end + +--[[ + 检查节点是否存在 + @param node 节点名称 + @return 节点是否存在 +]] +function ini:exist_node(node) + return self.module:exist_node(node) +end + +--[[ + 转为table +]] +function ini:table() + return self.module:table() +end + +-- 构造函数 +function ini.new() + local instance = setmetatable({}, ini) + instance.module = fw_ini.new() + return instance +end + +return ini diff --git a/target/fastweb/interceptor.lua b/target/fastweb/interceptor.lua new file mode 100644 index 0000000..7900f82 --- /dev/null +++ b/target/fastweb/interceptor.lua @@ -0,0 +1,46 @@ +-- 拦截器 +local M = {} + + +M.module = fw_interceptor + +--[[ +FUNCTION: 增加规则 +PARAM + express : 规则 + filepath : LUA脚本 +--]] +function M.add(express,filepath) + M.module.add(express,filepath) +end + +--[[ +FUNCTION: 是否存在拦截规则 +PARAM + express : 规则 +RRETURN + `bool` +--]] +function M.exist(express) + return M.module.exist(express) +end + +--[[ +FUNCTION: 移除拦截规则 +PARAM + express : 规则 +RRETURN + `bool` +--]] +function M.remove(express) + return M.module.remove(express) +end + +--[[ +FUNCTION: 清空拦截器 +--]] +function M.clear(express) + return M.module.clear(express) +end + +return M diff --git a/target/fastweb/mutex.lua b/target/fastweb/mutex.lua new file mode 100644 index 0000000..a93f4af --- /dev/null +++ b/target/fastweb/mutex.lua @@ -0,0 +1,41 @@ +-- mutex.lua +local mutex = {} +mutex.__index = mutex + +--[[ + 构造函数,创建一个新的 fw_mutex 对象 + @return 返回一个新的 fw_mutex 对象 +]] +function mutex.new() + local instance = setmetatable({}, mutex) + instance.module = fw_mutex.new() + return instance +end + +--[[ + 加锁 +]] +function mutex:lock() + self.module:lock() +end + +--[[ + 释放锁 +]] +function mutex:unlock() + self.module:unlock() +end + +--[[ + 尝试加锁 + @return 是否成功加锁 +]] +function mutex:try_lock() + return self.module:try_lock() +end + +function mutex:self() + return self.module:self() +end + +return mutex diff --git a/target/fastweb/process.lua b/target/fastweb/process.lua new file mode 100644 index 0000000..089966d --- /dev/null +++ b/target/fastweb/process.lua @@ -0,0 +1,74 @@ +-- process.lua +local process = {} + +process.module = fw_process + +--[[ +FUNCTION: 创建进程 +PARAMS + filepath : 脚本文件路径 + working_directory : 工作目录 + args : 参数表 + wait_close : 是否等待关闭 + show_window : 是否显示窗口 +RETURN + `number` : 进程ID (PID),0表示失败 +]] +function process.create(filepath, working_directory, args, wait_close, show_window) + return process.module.create(filepath, working_directory, args, wait_close, show_window) +end + +--[[ +FUNCTION: 关闭进程 +PARAM + pid : 进程ID (PID) +RETURN + `bool` : 是否成功关闭 +]] +function process.destory(pid) + return process.module.destory(pid) +end + +--[[ +FUNCTION: 获取进程列表 +RETURN + `table` : 进程列表 +]] +function process.list() + return process.module.list() +end + +--[[ +FUNCTION: 检查文件路径是否存在 +PARAM + filepath : 文件路径 +RETURN + `table` : 检查结果 +]] +function process.exist(filepath) + return process.module.exist(filepath) +end + +--[[ +FUNCTION: 检查PID是否存在 +PARAM + pid : 进程ID (PID) +RETURN + `bool` : PID是否存在 +]] +function process.exist_pid(pid) + return process.module.exist_pid(pid) +end + +--[[ +FUNCTION: 获取PID路径 +PARAM + pid : 进程ID (PID) +RETURN + `string` : PID对应的路径 +]] +function process.getpath(pid) + return process.module.getpath(pid) +end + +return process diff --git a/target/fastweb/queue.lua b/target/fastweb/queue.lua new file mode 100644 index 0000000..c6bca99 --- /dev/null +++ b/target/fastweb/queue.lua @@ -0,0 +1,32 @@ +-- queue.lua +local queue = {} +queue.__index = queue + + +function queue.new() + local instance = setmetatable({}, queue) + instance.module = fw_queue.new() + return instance +end + +function queue:push(value) + self.module:push(value) +end + +function queue:pop() + return self.module:pop() +end + +function queue:size() + return self.module:pop() +end + +function queue:clear() + self.module:clear() +end + + +function queue:self() + return self.module:self() +end +return queue diff --git a/target/fastweb/request.lua b/target/fastweb/request.lua new file mode 100644 index 0000000..c98dd3f --- /dev/null +++ b/target/fastweb/request.lua @@ -0,0 +1,159 @@ +local session = require("fastweb.session") + + +local M = {} +--[[ +FUNCTION: 取协议头 +PARAM + name : 名称 +--]] +function M.header(name) + return fw_request:header(name) +end + + +--[[ +FUNCTION: 取协议头(表) +PARAM + name : 名称 +--]] +function M.headers() + return fw_request:headers() +end + +--[[ +FUNCTION: 取请求类型 +RETURN + 请求类型:GET, POST, PUT, DEL, HEAD 等 +--]] +function M.method() + return fw_request:method() +end + +--[[ +FUNCTION: 取请求路径 +--]] +function M.filepath() + return fw_request:filepath() +end + +--[[ +FUNCTION: 取请求主机 +--]] +function M.host() + return fw_request:host() +end + +--[[ +FUNCTION: 取请求参数 +DESC:支持BODY、URL和JSON一级属性的获取。 +PARAM + name : 参数名 + throw : 为空时是否抛出异常 +--]] +function M.param(name,throw) + return fw_request:param(name,throw) +end + +--[[ +FUNCTION: 取请求发起IP地址 +--]] +function M.remote_ipaddress() + return fw_request:remote_ipaddress() +end + +--[[ +FUNCTION: 取请求发起端口 +--]] +function M.remote_port() + return fw_request:remote_port() +end + +--[[ +FUNCTION: 取会话session +PARAM + session_id : 此ID自行维护唯一 +--]] +function M.session(session_id) + return session.new(fw_request:session(session_id)) +end + +--[[ +FUNCTION: 获取请求体参数表 +--]] +function M.body_param() + return fw_request:body_param() +end + +--[[ +FUNCTION: 获取URL参数表 +--]] +function M.url_param() + return fw_request:url_param() +end + +--[[ +FUNCTION: 获取请求体字符串 +--]] +function M.body() + return fw_request:body() +end + +--[[ +FUNCTION: 获取表单信息 +--]] +function M.multipart() + return fw_request:multipart() +end +--[[ +FUNCTION: 读取表单数据 +--]] +function M.multipart_content(id) + return fw_request:multipart_content(id) +end +--[[ +FUNCTION: 保存表单数据 +--]] +function M.multipart_content_save(id,filepath) + return fw_request:multipart_content_save(id,filepath) +end +--[[ +FUNCTION: 读取表单数据 +--]] +function M.multipart_content_name(name) + -- 按name字段查找对应的表单条目,取其id,然后调用multipart_content + local multipart_list = M.multipart() + for _, item in ipairs(multipart_list or {}) do + if item.param and item.param.name == name then + return M.multipart_content(item.id) + end + end + return nil +end +--[[ +FUNCTION: 置临时数据(仅本次请求有效) +--]] +function M.set(name,value) + fw_request:set(name,value) +end + +--[[ +FUNCTION: 取临时数据(仅本次请求有效) +--]] +function M.get(name) + return fw_request:get(name) +end +--[[ +FUNCTION: 取临时数据(仅本次请求有效) +--]] +function M.gets() + return fw_request:gets() +end +--[[ +FUNCTION: 保存请求体到文件 +--]] +function M.save_body(filepath) + return fw_request:save_body(filepath) +end + +return M diff --git a/target/fastweb/response.lua b/target/fastweb/response.lua new file mode 100644 index 0000000..6208c98 --- /dev/null +++ b/target/fastweb/response.lua @@ -0,0 +1,84 @@ +local M = {} + + +--[[ +FUNCTION: 发送字符串 +PARAM + value : 内容 +--]] +function M.send(value) + return fw_response:send(value) +end + +--[[ +FUNCTION: 发送字符串 +PARAM + value : 内容 + state_num : 状态码 + state_sec : 状态描述 +--]] +function M.sendex(value, state_num, state_esc) + return fw_response:sendex(value, state_num, state_esc) +end + +--[[ +FUNCTION: 发送文件 +PARAM + filepath : 文件路径 + downbaud : 限速每秒字节(-1=不限速) + state_num : 状态码 + state_sec : 状态描述 +--]] +function M.send_file(filepath, downbaud, state_num, state_desc) + return fw_response:send_file(filepath, downbaud, state_num, state_desc) +end + +--[[ +FUNCTION: 重定向请求 +PARAM + filepath : 文件路径 + MovedPermanently : 是否永久重定向 +--]] +function M.redirect(filepath,MovedPermanently) + return fw_response:redirect(filepath,MovedPermanently) +end + +--[[ +FUNCTION: 转发请求 +PARAM + filepath : 转发路径 +--]] +function M.forward(filepath) + return fw_response:forward(filepath) +end + +--[[ +FUNCTION: 设置响应头。 +PARAM + name : 名称 + value : 值 +--]] +function M.header(name, value) + fw_response:header(name, value) +end + +--[[ +FUNCTION: 置后端渲染。 +PARAM + name : 名称 + value : 值 +--]] +function M.set(name, value) + fw_response:set(name, value) +end + +--[[ +FUNCTION: 置后端渲染。 +PARAM + table : 名称 +--]] +function M.sets(tab) + fw_response:sets(tab) +end + +return M \ No newline at end of file diff --git a/target/fastweb/session.lua b/target/fastweb/session.lua new file mode 100644 index 0000000..b70ad18 --- /dev/null +++ b/target/fastweb/session.lua @@ -0,0 +1,61 @@ +local M = {} +M.__index = M + +function M.new(fwsession) + local instance = setmetatable({}, M) + instance.module = fwsession + return instance +end +--[[ +FUNCTION: 初始化会话对象 +PARAM + session_id : 会话ID +--]] +function M:init(id) + return self.module:init(fw_request,id) +end + +--[[ +FUNCTION: 取sessionid +--]] +function M:id() + return self.module:id() +end + +--[[ +FUNCTION: 更新 +DESC:用于更新过期时间等 +--]] +function M:update() + self.module:update() +end + + +--[[ +FUNCTION: 置会话属性 +PARAM + name : 名称 + value : 值 +--]] +function M:set(name,value) + self.module:set(name,value) +end + +--[[ +FUNCTION: 取会话属性 +PARAM + name : 名称 +--]] +function M:get(name) + return self.module:get(name) +end + +--[[ +FUNCTION: 检查会话有效性 +--]] +function M:check() + return self.module:check() +end + + +return M \ No newline at end of file diff --git a/target/fastweb/subscribe.lua b/target/fastweb/subscribe.lua new file mode 100644 index 0000000..cfb1579 --- /dev/null +++ b/target/fastweb/subscribe.lua @@ -0,0 +1,46 @@ +-- 拦截器 +local M = {} + + +M.module = fw_subscribe + +--[[ +FUNCTION: 增加订阅 +PARAM + express : 规则 + filepath : LUA脚本 +--]] +function M.add(express,filepath) + M.module.add(express,filepath) +end + +--[[ +FUNCTION: 是否存在订阅规则 +PARAM + express : 规则 +RRETURN + `bool` +--]] +function M.exist(express) + return M.module.exist(express) +end + +--[[ +FUNCTION: 移除订阅规则 +PARAM + express : 规则 +RRETURN + `bool` +--]] +function M.remove(express) + return M.module.remove(express) +end + +--[[ +FUNCTION: 清空订阅 +--]] +function M.clear(express) + return M.module.clear(express) +end + +return M diff --git a/target/fastweb/timer.lua b/target/fastweb/timer.lua new file mode 100644 index 0000000..2c44e72 --- /dev/null +++ b/target/fastweb/timer.lua @@ -0,0 +1,38 @@ +-- timer.lua +local timer = {} +timer.__index = timer + +--[[ + 创建一个新的 fw_timer 对象 + @return 返回一个新的 fw_timer 对象 +]] +function timer.new() + local instance = setmetatable({}, timer) + instance.module = fw_timer.new() + return instance +end + +--[[ + 增加一个定时器 + @param name 定时器名称 + @param filepath LUA脚本文件路径 + @param msec 时间间隔(毫秒) + @return 返回一个字符串标识 +]] +function timer:add(name, filepath, msec) + return self.module:add(name, filepath, msec) +end + +--[[ + 移除一个定时器 + @param name 定时器名称 +]] +function timer:remove(name) + self.module:remove(name) +end + + +function timer:self() + return self.module:self() +end +return timer