如何设置Lua资源的路径

我想尝试一些 Lua 客户端和 Java 服务器,我看到了这个问题:

如何在 Lua 中获取 TCP 回复?:

服务器:

import java.net.*;
import java.io.*;
public class server {
    public static void main(String args[]) throws Exception {
        ServerSocket server = null;
        Socket client = null;
        PrintStream out = null;
        BufferedReader buf = null;
        server = new ServerSocket(8000);
        client = server.accept();
        buf = new BufferedReader(
                new InputStreamReader(client
                  .getInputStream()));
        out = new PrintStream(
                client.getOutputStream());
        String str = buf.readLine();
        out.println("Echo:"+str);
        System.out.println("HELLO"+str);
        out.close();
        client.close();
    }
};

客户端:

local socket = require("socket")

local host = "127.0.0.1"
local port = 8000
local sock = assert(socket.connect(host, port))
sock:settimeout(10)

print("Press enter after input something:")

local input, recvt, sendt, status
input = io.read()
if #input > 0 then
    assert(sock:send(input .. "\n"))
end
local response, receive_status = sock:receive()
print(response)

我看不到如何设置到 Lua API、库/ Lua 组件的路径 - 我该如何设置它?

点赞
用户646619
用户646619

在 Lua 虚拟机中,Lua 包使用 package.path,C API 包使用 package.cpath。它们最初被设置为 LUA_PATHLUA_CPATH 环境变量。路径使用分号(;)分隔。详情请参考package.pathpackage.cpath

2014-06-25 15:28:57