Skip to content

Luajsocket is a port of the luasocket library to luaj. It allows for easy socket communication inside lua scripts running in a luaj vm.

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

AlexanderSchuetz97/luajsocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

luajsocket

Luajsocket is a port of the luasocket library to luaj. It allows for easy socket communication inside lua scripts running in a luaj vm.

License

Luajsocket is released under the GNU Lesser General Public License Version 3.
A copy of the GNU Lesser General Public License Version 3 can be found in the COPYING & COPYING.LESSER files.

Luajsocket contains components sourced from the luasocket library.
Those components are all contained within the folder "src/main/lua/luasocket".
All files in the folder "src/main/lua/luasocket" are released under the LuaSocket 3.0 license.
A copy of the LuaSocket 3.0 license can be found in the src/main/lua/luasocket/LICENSE file.
For more information regarding luasocket see:
https://github.com/diegonehab/luasocket/

Dependencies

  • Java 7 or newer
  • luaj version 3.0.1

Usage

Maven:

<!-- https://mvnrepository.com/artifact/io.github.alexanderschuetz97/luajsocket -->
<dependency>
    <groupId>io.github.alexanderschuetz97</groupId>
    <artifactId>luajsocket</artifactId>
    <version>0.1.3</version>
</dependency>

In Java:

Globals globals = JsePlatform.standardGlobals();
globals.load(new LuaJSocketLib());
//.... (Standart LuaJ from this point)
globals.load(new InputStreamReader(new FileInputStream("test.lua")), "test.lua").call();

In test.lua:

local socket = require('socket')
-- Using socket.gettime() as an example here to see if library was loaded.
print("Seconds since Jan 1st 1970 ", tostring(socket.gettime()))

How to compile luajsocket

It is recommended to uncomment the maven-gpg-plugin section from the pom.xml before building. Alternatively you may build it by passing "-Dgpg.skip" as a maven parameter.

If you do not want to run the junit tests then pass "-DskipTests"
The Junit tests may fail because they will bind a couple of local ports to test Socket functionalities.
If those ports happen to be occupied on your system then the tests will fail your build.

Not implemented / tested yet

calling socket.select on udp sockets is not implemented yet.

All functions from smtp.lua are not tested due to them not being testable
without settings up an entire smtp server.
Since this file was copied from luasocket it should just work.

Advanced http functions from http.lua are not tested.
Since this file was copied from luasocket it should just work.

ftp upload from ftp.lua is not tested.
Since this file was copied from luasocket it should just work.

Debugging Luaj using mobdebug.lua

Using luajsocket you can finally debug luaj code using any lua ide that supports "mobdebug.lua"
Similar libraries will probably work too. "mobdebug.lua" is known to be working.
Unfortunately luaj's DebugLib behaves different from the standard lua debug library.
DebugLib does not track the stack of the luavm while inside the hook function.
"mobdebug.lua" requires this however.
To debug using mobdebug.lua a different DebugLib has to be used.

In Java:

//Do not use the debug globals! They will not work!
Globals globals = JsePlatform.standardGlobals();

//This class comes with luajsocket because 
//it only required very minor adjustments to make it work
globals.load(new MobDebugCompatibleDebugLib()); 

globals.load(new LuaJSocketLib());
//.... (Standart LuaJ from this point)
globals.load(new InputStreamReader(new FileInputStream("test.lua")), "test.lua").call();

In test.lua:

-- Subsitute this with your path to mobdebug.lua
-- The one from github or ZeroBrane Studio works just fine
mobdebug = dofile("mobdebug.lua")

-- this call will try to connect to a mobdebug debugging server on the local machine
-- use an IDE like ZeroBrane Studio to create this server. 
-- You may also specify IP+port for remote debugging 
mobdebug.start()

local x = 1
-- set a breakpoint before this print in the IDE
print(x) 
Further info on using mobdebug to debug luaj

Using the EmmyLua Debugger in IntelliJ will work,
however EmmyLua will crash when you use the evaluate feature with a syntax error.
This is because luaj creates a multi line error string that mobdebug.lua will send
over the network. EmmyLua will not expect a multi line string. You will have
to patch the error message in mobdebug.lua before it is sent to always be
a static message like "Error happened" then it won't crash the debugger.
ZeroBrane Studio does not suffer from this issue and thus does not require a patch.

Additionally, the debugger will require you to give your lua "chunks" proper names.
The chunk name can be set by the second parameter to globals.load.
ZeroBrane Studio requires the name to be the file name that is open inside of it.
Ex: literally "test.lua"
EmmyLua requires the full absolute path to the file to be the chunk name.
If it does not find the file by its absolute path it will look for a relative path starting in the user home directory.
The only way to be "compatible" with both debuggers at the same time
is to place (or copy) your lua files to your home directory.

About

Luajsocket is a port of the luasocket library to luaj. It allows for easy socket communication inside lua scripts running in a luaj vm.

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published