Integrating Luasocket into C + +

Source: Internet
Author: User
Tags lua

Build a project Pro_test, create a run directory test;

Copy the *.lua in the Luasocket/src folder to the Test/src folder;

Copy the Socket.dll,mime.dll,lua5.1.dll to the test folder;

Change the Socket.lua to Socket_wrap.lua, because Socket.lua and socket.dll have duplicate names;

Main.cpp:

#include <stdio.h>extern "C"{#include"luasocket.h"#include"lua.h"#include"Lualib.h"#include"Lauxlib.h"#include"luaconf.h"};intMainintNarg,Char*args[]) {Lua_state* L =lual_newstate ();    Luaopen_base (L);    Lual_openlibs (L);    Luaopen_socket_core (L); intret = Lual_dofile (L, args[1]); if(Ret! =0) {printf ("%s", Lua_tostring (L,-1)); }    return 0;}

Main.lua:

' 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 ();

Integrating Luasocket into C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.