# lua_projs_20240120 **Repository Path**: linux2014/lua_projs_20240120 ## Basic Information - **Project Name**: lua_projs_20240120 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-21 - **Last Updated**: 2025-06-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README --- --- ### lua项目教程: https://blog.csdn.net/qq_41044598/article/details/126234861 https://blog.csdn.net/weixin_46203834/article/details/143262324 https://blog.csdn.net/weixin_34146805/article/details/88696224 --- ### 运行lua项目: ``` lua main.lua ``` ### 多文件项目: 需要在全局变量package.path中添加lua源文件的搜索路径; 在主调源码文件内引入库,并调用库中的函数; =require("") .() --- ### lua多文件项目: #### 1,文件结构: ``` your_project/ │ ├── main.lua │ ├── modules/ │ ├── module1.lua │ ├── module2.lua │ └── module3.lua │ └── libs/ ├── library1.lua └── library2.lua ``` #### 2,编写模块: ``` -- modules/module1.lua local M = {} function M.sayHello() print("Hello from Module 1") end return M ``` #### 3,使用模块: ``` -- main.lua local module1 = require("modules.module1") module1.sayHello() -- 输出: Hello from Module 1 ``` #### 4,使用第三方库: 如果你需要使用第三方库,可以按照类似的方式加载它们。例如,如果你有一个名为library1.lua的库: ``` -- libs/library1.lua local L = {} function L.doSomething() print("Doing something useful") end return L ``` 引用: ``` -- main.lua 或其他模块文件 local library1 = require("libs.library1") library1.doSomething() -- 输出: Doing something useful ``` #### 5,组织大型项目(可选) 对于大型项目,你可能会考虑更复杂的组织方式,例如将相关模块放在不同的子目录中,或者使用更高级的依赖管理工具(虽然Lua本身不直接支持包管理工具如npm或pip,但可以通过一些工具如LuaRocks来实现)。例如,使用LuaRocks来管理依赖: ``` luarocks install luafilesystem # 安装一个库作为示例 ``` 引用: ``` local lfs = require("lfs") -- 加载LuaRocks安装的库 ``` #### 6,测试和调试: ``` busted test/test_module1.lua # 运行测试文件 ``` #### 7,打包和分发(可选): ``` luarocks make rockspec # 使用rockspec文件创建包,rockspec是一个描述你的项目的文件,包括依赖等元数据。 ``` --- ### lua项目打包: https://docs.pingcode.com/baike/2838081 #### 1,用luac编译成字节码文件,执行字节码文件; 编译: ``` luac -o main.luac main.lua ``` 执行: ``` lua main.luac ``` #### 2,用luarocks打包成可执行文件; ``` luarocks write_rockspec --lua-versions=5.3 ``` ``` luarocks make # 使用rockspec文件创建包,rockspec是一个描述你的项目的文件,包括依赖等元数据。需要替换成上一步生成的rockspec文件名。 ``` ``` D:\D\i_projs\lua_projs_20240120>luarocks config --local lua_dir "D:\D\install_dir\lua_v532\bin" Error: Cannot create file at C:/Users/jintao.wang/AppData/Roaming/luarocks/config-5.3.lua D:\D\i_projs\lua_projs_20240120>mkdir "C:\Users\jintao.wang\AppData\Roaming\luarocks" D:\D\i_projs\lua_projs_20240120>luarocks config --local lua_dir "D:\D\install_dir\lua_v532\bin" Wrote lua_interpreter = "lua.exe" variables.LUA_BINDIR = "D:\\D\\install_dir\\lua_v532\\bin" variables.LUA_DIR = "D:\\D\\install_dir\\lua_v532\\bin" to C:/Users/jintao.wang/AppData/Roaming/luarocks/config-5.3.lua D:\D\i_projs\lua_projs_20240120> ``` --- ### lua打包: https://blog.csdn.net/weixin_34291004/article/details/91948338 --- --- ### lua调用C/C++实现的动态库: https://www.cnblogs.com/l2017/p/11365550.html https://www.cnblogs.com/chetwin/p/16726404.html --- --- ### lua,love2d ### love2d: https://www.love2d.org/ https://wenku.baidu.com/view/300f506a13a6f524ccbff121dd36a32d7275c706.html?_wkts_=1705766199569&bdQuery=love2d https://blog.csdn.net/qq_44918090/category_11757733.html https://blog.csdn.net/weixin_44341535/article/details/101516893?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7EPaidSort-1-101516893-blog-124196069.235%5Ev40%5Epc_relevant_rights_sort&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7EPaidSort-1-101516893-blog-124196069.235%5Ev40%5Epc_relevant_rights_sort&utm_relevant_index=1 ### lua: https://blog.csdn.net/qq_41044598/article/details/126234861 https://blog.csdn.net/weixin_37625173/article/details/132631999 --- ``` main.lua love.load() love.update(dt) love.draw() love.keypressed(key) love.mousepressed(x,y,button) love.quit() 每一个游戏循环哪要做的工作: 1,更新游戏逻辑; 2,重绘画面; 3,重新显示画面; ``` --- ### ---