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 + +