zoukankan      html  css  js  c++  java
  • 把luasocket集成到c++中

    建一个项目pro_test,创建一个运行目录test;

    把luasocket/src文件夹中的*.lua拷贝到test/src文件夹中;

    把socket.dll,mime.dll,lua5.1.dll拷贝到test文件夹中;

    把socket.lua改为socket_wrap.lua,因为socket.lua和socket.dll重名了;

    main.cpp:

    #include <stdio.h>
    
    extern "C" 
    {
        #include "luasocket.h"
        #include "lua.h"
        #include "lualib.h"
        #include "lauxlib.h"
        #include "luaconf.h"
    };
    
    int main(int narg, char* args[])
    {
        lua_State* L = luaL_newstate();
        luaopen_base(L);
        luaL_openlibs(L);
    
        luaopen_socket_core(L);
    
        int ret = luaL_dofile(L, args[1]);
        if(ret != 0)
        {
            printf("%s", lua_tostring(L, -1));
        }
        return 0;
    }

    main.lua:

    package.path = 'D:/xxx/test/src/?.lua;'
    require("socket_wrap")
    local socket = require("socket")
    local server = assert(socket.bind("*", 0))
    local ip, port = server:getsockname()
    print("server open on port " .. port)
    local client = server:accept();
  • 相关阅读:
    通过dockerfile制作nginx镜像
    docker存储卷
    docker容器网络配置
    状态模式
    抽象工厂模式
    观察者模式
    建造者模式
    外观模式
    模板方法模式
    原型模式
  • 原文地址:https://www.cnblogs.com/afan/p/6290433.html
Copyright © 2011-2022 走看看