制作购物网站教程/网站优化推广排名

制作购物网站教程,网站优化推广排名,深圳福永,网站开发国内外研究现状文章目录 介绍Extensions Modulesbit.* — Bitwise operationsffi.* — FFI libraryjit.* — JIT compiler controlC API extensionsProfiler Enhanced Standard Library Functionsxpcall(f, err [,args...]) passes arguments例子: xpcall 的使用 load*() handle U…

文章目录

    • 介绍
    • Extensions Modules
      • `bit.*` — Bitwise operations
      • `ffi.*` — FFI library
      • `jit.*` — JIT compiler control
      • C API extensions
      • Profiler
    • Enhanced Standard Library Functions
      • `xpcall(f, err [,args...])` passes arguments
        • 例子: xpcall 的使用
      • `load*()` handle UTF-8 source code
        • 例子:变量名是中文
      • `load*()` add a mode parameter
      • `string.dump(f [,mode])` generates portable bytecode
      • `table.new(narray, nhash)` allocates a pre-sized table
        • 例子:table.new 的使用
      • `table.clear(tab)` clears a table
        • 例子:table.clear 的使用
      • Enhanced PRNG for `math.random()`
      • `io.*` functions handle 64 bit file offsets
      • `debug.*` functions identify metamethods
    • Fully Resumable VM
        • 例子:协程在 pcall 中 yield
        • 例子:协程在迭代器中 yield
    • Extensions from Lua 5.2
        • 例子:goto 的使用
        • 例子:'\z'转义字符的使用
        • 例子:package.loadlib 的使用
    • Extensions from Lua 5.3

介绍

LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language. Lua is a powerful, dynamic and light-weight programming language. It may be embedded or used as a general-purpose, stand-alone language.

LuaJIT is fully upwards-compatible with Lua 5.1. It supports all standard Lua library functions and the full set of Lua/C API functions.

LuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic loader level. This means you can compile a C module against the standard Lua headers and load the same shared library from either Lua or LuaJIT.

LuaJIT extends the standard Lua VM with new functionality and adds several extension modules. Please note, this page is only about functional enhancements and not about performance enhancements, such as the optimized VM, the faster interpreter or the JIT compiler.

Extensions Modules

LuaJIT comes with several built-in extension modules:

bit.* — Bitwise operations

LuaJIT supports all bitwise operations as defined by Lua BitOp:

bit.tobit  bit.tohex  bit.bnot    bit.band bit.bor  bit.bxor
bit.lshift bit.rshift bit.arshift bit.rol  bit.ror  bit.bswap

This module is a LuaJIT built-in — you don’t need to download or install Lua BitOp. The Lua BitOp site has full documentation for all Lua BitOp API functions. The FFI adds support for 64 bit bitwise operations, using the same API functions.

Please make sure to require the module before using any of its functions:

local bit = require("bit")

An already installed Lua BitOp module is ignored by LuaJIT. This way you can use bit operations from both Lua and LuaJIT on a shared installation.

ffi.* — FFI library

The FFI library allows calling external C functions and the use of C data structures from pure Lua code【重点】.

jit.* — JIT compiler control

The functions in this module control the behavior of the JIT compiler engine.

C API extensions

LuaJIT adds some extra functions to the Lua/C API.

Profiler

LuaJIT has an integrated profiler.

Enhanced Standard Library Functions

xpcall(f, err [,args...]) passes arguments

Unlike the standard implementation in Lua 5.1, xpcall() passes any arguments after the error function to the function which is called in a protected context.

例子: xpcall 的使用
local function divide(a, b)if b == 0 thenerror("Division by zero")endreturn a / b
endlocal function error_handler(err)return "Handled error: " .. err
endlocal function safe_divide(a, b)local status, result = xpcall(divide, error_handler, a, b)if status thenreturn resultelseprint("Custom Error Handler: " .. result)  -- 自定义错误处理return nilend
endprint(safe_divide(10, 2))  -- 输出:5
print(safe_divide(10, 0))  -- 输出:Custom Error Handler: Handled error: Division by zero

load*() handle UTF-8 source code

Non-ASCII characters are handled transparently by the Lua source code parser. This allows the use of UTF-8 characters in identifiers and strings. A UTF-8 BOM is skipped at the start of the source code.

例子:变量名是中文
local 姓名 = "张三"
local 年龄 = 25print("姓名:" .. 姓名)
print("年龄:" .. 年龄)

使用标准的lua5.1会语法报错

load*() add a mode parameter

As an extension from Lua 5.2, the functions loadstring(), loadfile() and (new) load() add an optional mode parameter.

The default mode string is "bt", which allows loading of both source code and bytecode. Use "t" to allow only source code or "b" to allow only bytecode to be loaded.

By default, the load* functions generate the native bytecode format. For cross-compilation purposes, add W to the mode string to force the 32 bit format and X to force the 64 bit format. Add both to force the opposite format. 【同时使用 WX 来强制使用与本机平台相反的字节码格式】Note that non-native bytecode generated by load* cannot be run, but can still be passed to string.dump.

string.dump(f [,mode]) generates portable bytecode

An extra argument has been added to string.dump(). If set to true or to a string which contains the character s, ‘stripped’ bytecode without debug information is generated. This speeds up later bytecode loading and reduces memory usage. See also the -b command line option.

The generated bytecode is portable and can be loaded on any architecture that LuaJIT supports. However, the bytecode compatibility versions must match. Bytecode only stays compatible within a major+minor version (x.y.aaa → x.y.bbb), except for development branches. Foreign bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.

Note: LJ_GC64 mode requires a different frame layout, which implies a different, incompatible bytecode format between 32 bit and 64 bit ports. This may be rectified in the future. In the meantime, use the W and X modes of the load* functions for cross-compilation purposes.

Due to VM hardening, bytecode is not deterministic. Add d to the mode string to dump it in a deterministic manner: identical source code always gives a byte-for-byte identical bytecode dump. This feature is mainly useful for reproducible builds.

table.new(narray, nhash) allocates a pre-sized table

An extra library function table.new() can be made available via require("table.new"). This creates a pre-sized table, just like the C API equivalent lua_createtable(). This is useful for big tables if the final table size is known and automatic table resizing is too expensive.

例子:table.new 的使用
require("table.new")t = table.new(1,1)
t[1] = 1
t["a"] = 2
print(type(t)) -- table

table.clear(tab) clears a table

An extra library function table.clear() can be made available via require("table.clear"). This clears all keys and values from a table, but preserves the allocated array/hash sizes. This is useful when a table, which is linked from multiple places, needs to be cleared and/or when recycling a table for use by the same context. This avoids managing backlinks, saves an allocation and the overhead of incremental array/hash part growth.

Please note, this function is meant for very specific situations. In most cases it’s better to replace the (usually single) link with a new table and let the GC do its wo

例子:table.clear 的使用
local tab = {1, 2, 3, a = 10, b = 20}-- 清空表,但保留表的内存分配
require("table.clear")  -- 确保你加载了这个扩展函数
table.clear(tab)-- 现在 tab 变成了空表,但它的内存结构(数组和哈希大小)没有改变
print(next(tab))  -- 输出 nil,因为表已经没有内容了

Enhanced PRNG for math.random()

LuaJIT uses a Tausworthe PRNG with period 2^223 to implement math.random() and math.randomseed(). The quality of the PRNG results is much superior compared to the standard Lua implementation, which uses the platform-specific ANSI rand().

The PRNG generates the same sequences from the same seeds on all platforms and makes use of all bits in the seed argument. math.random() without arguments generates 52 pseudo-random bits for every call. The result is uniformly distributed between 0.0 and 1.0. It’s correctly scaled up and rounded for math.random(n [,m]) to preserve uniformity.

Call math.randomseed() without any arguments to seed it from system entropy.

Important: Neither this nor any other PRNG based on the simplistic math.random() API is suitable for cryptographic use.

io.* functions handle 64 bit file offsets

The file I/O functions in the standard io.* library handle 64 bit file offsets. In particular, this means it’s possible to open files larger than 2 Gigabytes and to reposition or obtain the current file position for offsets beyond 2 GB (fp:seek() method).

debug.* functions identify metamethods

debug.getinfo() and lua_getinfo() also return information about invoked metamethods. The namewhat field is set to "metamethod" and the name field has the name of the corresponding metamethod (e.g. "__index").

Fully Resumable VM

The LuaJIT VM is fully resumable. This means you can yield from a coroutine even across contexts, where this would not possible with the standard Lua 5.1 VM: e.g. you can yield across pcall() and xpcall(), across iterators and across metamethods.

例子:协程在 pcall 中 yield
local function testCoroutine()pcall(function()print("Start coroutine")coroutine.yield() -- 在这里挂起协程print("Resumed coroutine")end)
endlocal co = coroutine.create(testCoroutine)coroutine.resume(co) -- 启动协程
coroutine.resume(co) -- 恢复协程

输出

Start coroutine
Resumed coroutine

而在标准的lua5.1中只输出

Start coroutine
例子:协程在迭代器中 yield
local coroutine = require("coroutine")-- 一个自定义的迭代器,它会在每次返回一个元素时进行yield
function my_iterator(start, _end)local i = startreturn function()if i <= _end thencoroutine.yield()  -- 在返回每个元素时进行yieldi = i + 1return i - 1endend
end-- 创建一个协程来使用迭代器
local co = coroutine.create(function()for value in my_iterator(1, 5) doprint("迭代值: ", value)-- 在这里可以插入一些逻辑,例如,暂停协程,模拟某些异步操作end
end)-- 在主线程中控制协程的恢复
while coroutine.status(co) ~= "dead" doprint("恢复协程")coroutine.resume(co)-- 每次恢复时迭代器会继续从`yield`的位置往下执行
end

输出

恢复协程
恢复协程
迭代值:         1
恢复协程
迭代值:         2
恢复协程
迭代值:         3
恢复协程
迭代值:         4
恢复协程
迭代值:         5

而标准的lua5.1输出

恢复协程

Extensions from Lua 5.2

LuaJIT supports some language and library extensions from Lua 5.2. Features that are unlikely to break existing code are unconditionally enabled:

  • goto and ::labels::.
例子:goto 的使用
local i = 0::start::  -- 标签定义if i < 5 thenprint("i is " .. i)i = i + 1goto start  -- 跳回到 start 标签
endprint("Finished")
  • Hex escapes '\x3F' and '\z' escape in strings.

The escape sequence ‘\z’ skips the following span of white-space characters, including line breaks; it is particularly useful to break and indent a long literal string into multiple lines without adding the newlines and spaces into the string contents.

例子:'\z’转义字符的使用
local long_str ="This is a very long string that we\zwant to break into multiple lines,\zbut without including the newlines\zor spaces in the actual string content."print(long_str)

A byte in a literal string can also be specified by its numerical value. This can be done with the escape sequence \xXX, where XX is a sequence of exactly two hexadecimal digits, or with the escape sequence \ddd, where ddd is a sequence of up to three decimal digits. (Note that if a decimal escape is to be followed by a digit, it must be expressed using exactly three digits.) Strings in Lua can contain any 8-bit value, including embedded zeros, which can be specified as ‘\0’.

  • load(string|reader [, chunkname [,mode [,env]]]).
  • loadstring() is an alias for load().
  • loadfile(filename [,mode [,env]]).
  • math.log(x [,base]).
  • string.rep(s, n [,sep]).
  • string.format(): %q reversible. %s checks __tostring. %a and "%A added.
  • String matching pattern %g added.【%g: represents all printable characters except space.】
  • io.read("*L").【\*L”: reads the next line keeping the end of line (if present), returning nil on end of file.】
  • io.lines() and file:lines() process io.read() options.【和 io.read() 函数一样的参数】
  • os.exit(status|true|false [,close]).
  • package.searchpath(name, path [, sep [, rep]]).
  • package.loadlib(name, "*").
例子:package.loadlib 的使用

假设你有两个 C 库:libcore.so 和 libext.so。libext.so 依赖于 libcore.so,但是你不想让 libcore.so 的函数直接暴露到 Lua 环境中,而是只需要确保它的符号可以在 libext.so 中使用。

-- 仅仅加载 libcore.so,并确保符号链接到 Lua 环境中
package.loadlib("libcore.so", "*")-- 加载并使用 libext.so(它依赖于 libcore.so 的符号)
package.loadlib("libext.so", "luaopen_libext")
  • debug.getinfo() returns nparams and isvararg for option "u".
  • debug.getlocal() accepts function instead of level.
  • debug.getlocal() and debug.setlocal() accept negative indexes for varargs.
  • debug.getupvalue() and debug.setupvalue() handle C functions.
  • debug.upvalueid() and debug.upvaluejoin().
  • Lua/C API extensions: lua_version() lua_upvalueid() lua_upvaluejoin() lua_loadx() lua_copy() lua_tonumberx() lua_tointegerx() luaL_fileresult() luaL_execresult() luaL_loadfilex() luaL_loadbufferx() luaL_traceback() luaL_setfuncs() luaL_pushmodule() luaL_newlibtable() luaL_newlib() luaL_testudata() luaL_setmetatable()
  • Command line option -E.
  • Command line checks __tostring for errors.

Extensions from Lua 5.3

LuaJIT supports some extensions from Lua 5.3:

  • Unicode escape '\u{XX...}' embeds the UTF-8 encoding in string literals.【支持 Unicode 转义!】
  • The argument table arg can be read (and modified) by LUA_INIT and -e chunks.
  • io.read() and file:read() accept formats with or without a leading *.
  • assert() accepts any type of error object.
  • table.move(a1, f, e, t [,a2]).

Moves elements from table a1 to table a2, performing the equivalent to the following multiple assignment: a2[t],··· = a1[f],···,a1[e]. The default for a2 is a1. The destination range can overlap with the source range. The number of elements to be moved must fit in a Lua integer.

Returns the destination table a2.

  • coroutine.isyieldable().

Returns 1 if the given coroutine can yield, and 0 otherwise.

  • Lua/C API extensions: lua_isyieldable()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/897627.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

DeepSeek结合Mermaid绘图(流程图、时序图、类图、状态图、甘特图、饼图)转载

思维速览&#xff1a; 本文将详细介绍如何利用DeepSeek结合Mermaid语法绘制各类专业图表&#xff0c;帮助你提高工作效率和文档质量。 ▍DeepSeek入门使用请看&#xff1a;deepseek保姆级入门教程&#xff08;网页端使用 本地客户端部署 使用技巧&#xff09; DeepSeek官网…

上下分层、左右分离的驱动设计思想

之前了解了最简单的驱动程序、但是不易扩展、现在继续学习、上下分层、左右分离的驱动设计思想。 1、led_dev.c函数 上层函数&#xff0c;①定义一个结构体&#xff0c;存储函数用来接应app的函数。②定义一个入口函数&#xff0c;将我们接应的函数告诉内核&#xff0c;给这个…

《历史代码分析》5、动态控制列表的列

​​ 本系列《历史代码分析》为工作中遇到具有代表性的代码。今天我们讲一下&#xff0c;动态展示列表的列&#xff0c;因为找不到代码了&#xff0c;所有本篇用图展示。 举个栗子 ​​ 我们希望能够动态的控制列表的列&#xff0c;例如&#xff0c;英语老师只想知道自己学…

Windows HD Video Converter Factory PRO-v27.9.0-

Windows HD Video Converter Factory PRO 链接&#xff1a;https://pan.xunlei.com/s/VOL9TaiuS7rXbu-1kEDndoceA1?pwd7qch# 支持300多种视频格式转换&#xff0c;在保留视频质量的同时&#xff0c;压缩率可达80%&#xff0c;转换速度可达50X速率&#xff01; 支持画面剪切、片…

##Hive安装-初始化元数据报错 *** schemaTool failed ***

报错&#xff1a; org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version. Underlying cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure 解决方案&#xff1a; 尝试一&#xff1a;javax.jdo.o…

远程手机遥控开关原理及应用

远程手机遥控开关的工作原理主要是通过互联网传递无线信号&#xff0c;控制用电器的一种智能家居产品。 远程手机遥控开关的基本套件包括&#xff1a;手机APP、网线、家用WIFI中转无服务器或者是工厂提供的自带网线端口的中转服务器、连接用电器的接收器。使用时&#xff0c;手…

Mac java全栈开发环境配置

前言 由于最近手中的windows本子坏了,所以搞了一台m系列的macbookpro 作为一个开发者 面对新设备最先考虑的应该就是各种sdk、中间件服务、环境变量配置和工具了吧!!! 本文将带你手把手学习Mac搭建属于自己的本地开发环境 安装brew 什么是brew? ‌Brew(全称Homebrew)…

HTMLCSS绘制三角形

1.代码&#xff1a; <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>01triangle</title><s…

vue3-element-admin 前后端本地启动联调

一、后端环境准备 1.1、下载地址 gitee 下载地址 1.2、环境要求 JDK 17 1.3、项目启动 克隆项目 git clone https://gitee.com/youlaiorg/youlai-boot.git数据库初始化 执行 youlai_boot.sql 脚本完成数据库创建、表结构和基础数据的初始化。 修改配置 application-dev.y…

WinForm模态与非模态窗体

1、模态窗体 1&#xff09;定义&#xff1a; 模态窗体是指当窗体显示时&#xff0c;用户必须先关闭该窗体&#xff0c;才能继续与应用程序的其他部分进行交互。 2&#xff09;特点&#xff1a; 窗体以模态方式显示时&#xff0c;会阻塞主窗体的操作。用户必须处理完模态窗体上…

Agisoft Metashape 创建分块建模

Agisoft Metashape 创建分块建模 文章目录 Agisoft Metashape 创建分块建模前言一、构建分块模型1.1、设置模型范围1.2、参数设置二、构建纹理三、导出分块模型3.1整体导出3.2单独导出选定的分块四、编辑分块模型前言 从 Agisoft Metashape Professional 的 2.1. 版本开始,就…

MinIO的预签名直传机制

我们传统使用MinIo做OSS对象存储的应用方式往往都是在后端配置与MinIO的连接和文件上传下载的相关接口&#xff0c;然后我们在前端调用这些接口完成文件的上传下载机制&#xff0c;但是&#xff0c;当并发量过大&#xff0c;频繁访问会对后端的并发往往会对服务器造成极大的压力…

手把手教你用Docker搭建gitlab

文章目录 前言一、安装Docker二、安装GItlab三、配置Gitlab四、备份五、Docker数据持久化总结 前言 如题所述&#xff0c;手把手带你搭建gitlab&#xff0c;目标是实现ssh链接clone项目&#xff0c;不会我随你怎么说。 说正题&#xff0c;GitLab 是一个基于 Git 的全面 DevOps…

基于springboot住院管理系统(源码+lw+部署文档+讲解),源码可白嫖!

摘要 随着世界经济信息化、全球化的到来和电子商务的飞速发展&#xff0c;推动了很多行业的改革。若想达到安全&#xff0c;快捷的目的&#xff0c;就需要拥有信息化的组织和管理模式&#xff0c;建立一套合理、畅通、高效的线上管理系统。当前的住院管理存在管理效率低下&…

数据采集技术之python网络爬虫(中国天气网的爬取)

一、爬取中国天气网所有地区当天的天气数据&#xff08;PyCharm&#xff09;&#xff1a; 网址&#xff1a;https://www.weather.com.cn/ 下面爬取数据&#xff1a; 因为现在已经到了夜间&#xff0c;所以白天的数据已经不见了&#xff0c;但原理是一样的。 二、代码以及详情…

Ollama本地部署deepseek-r1蒸馏版

Docker安装Ollama 拉取镜像 docker pull ollama/ollama​ 启动-使用GPU docker run -d --gpusall -p 11434:11434 --name ollama ollama/ollamadocker run : Docker 的核心命令&#xff0c;用于创建并启动一个新的容器。 -d : 后台模式&#xff08;detached mode&#xff09…

41.HarmonyOS NEXT Layout布局组件系统详解(八):自定义样式与类

温馨提示&#xff1a;本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦&#xff01; HarmonyOS NEXT Layout 布局组件系统详解&#xff08;八&#xff09;&#xff1a;自定义样式与类 文章目录 HarmonyOS NEXT Layout 布局组件系统详…

【Go | 从0实现简单分布式缓存】-7:增加etcd和gRPC功能

本文目录 1.序2.引入etcd缓存流程项目结构 3.gocachepb.proto4.服务注册register.go5.服务发现discover.go6.gRPC客户端client.gopeers.goclient.go 7.gRPC服务端实现server.go一些问题缓存获取流程缓存设置流程为什么要带超时的上下文&#xff1f; 1.序 GeeCache项目并没有引…

Pytorch系列教程:可视化Pytorch模型训练过程

深度学习和理解训练过程中的学习和进步机制对于优化性能、诊断欠拟合或过拟合等问题至关重要。将训练过程可视化的过程为学习的动态提供了有价值的见解&#xff0c;使我们能够做出合理的决策。训练进度必须可视化的两种方法是&#xff1a;使用Matplotlib和Tensor Board。在本文…

18 | 实现简洁架构的 Handler 层

提示&#xff1a; 所有体系课见专栏&#xff1a;Go 项目开发极速入门实战课&#xff1b;欢迎加入我的训练营&#xff1a;云原生AI实战营&#xff0c;一个助力 Go 开发者在 AI 时代建立技术竞争力的实战营&#xff1b;本节课最终源码位于 fastgo 项目的 feature/s14 分支&#x…