README and licence stuff

This commit is contained in:
TSnake41 2020-02-27 18:38:21 +01:00
parent bfcdb200b5
commit ff1ceba0bc
11 changed files with 312 additions and 149 deletions

View File

@ -1 +1,58 @@
raylib-wren raylib binding.
![raylib-lua logo](assets/logo.png)
## raylib-lua
[LuaJIT](https://luajit.org/)-based binding for [raylib](https://www.raylib.com/), a simple and easy-to-use
library to learn videogames programming.
This binding is partially based on [raylib-wren/wray](https://github.com/TSnake41/raylib-wren).
### Usage (raylua_s)
raylua_s is the script-mode binary of raylib-lua.
Without any argument, you get into the REPL which gives you a minimal Lua
shell that allows you to run Lua code from terminal.
You can specify a Lua file as argument to run the specified Lua file.
### Usage (raylua_e)
raylua_e is the embedding-mode binary of raylib-lua.
This binary allows you to build standalone raylib applications from Lua code.
There are 3 ways to use it :
- zip mode :
If you specify a zip file as argument, this zip will be used as payload
application, this file expects to have a `main.lua` which is the entry point
of the application.
- directory mode :
Similar to zip mode except that it automatically build the zip payload from
the specified directory.
- lua mode :
Build the executable from a single Lua file.
Using `require` in embedded mode works as expected but `dofile` and `loadfile`
may not work as expected as these functions load from a external file rather
than from `package` loaders.
### Building / Updating Raylib / Contribution
To build raylib-lua from source, you need to take care that git submodules
are imported,
### Licence
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -18,7 +18,7 @@ all: raylua_s raylua_e
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
all: luajit raylib raylua_s raylua_e
all: raylua_s raylua_e luajit raylib
luajit:
$(MAKE) -C luajit amalg BUILDMODE=static
@ -32,7 +32,7 @@ raylua_s: src/raylua.o src/raylua_s.o
raylua_e: src/raylua.o src/raylua_e.o src/raylua_builder.o src/lib/miniz.o
$(CC) -o $@ $^ $(LDFLAGS)
src/raylua.o: src/autogen/boot.c src/autogen/bind.c
src/raylua.o: luajit raylib src/autogen/boot.c src/autogen/bind.c
src/raylua_builder.o: src/autogen/builder.c

View File

@ -1,3 +1,19 @@
--[[
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
print "[RAYLUA] Raylua boot script"
local ffi = require "ffi"

View File

@ -1,31 +1,47 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <raylib.h>
#include "autogen/bind.c"
#include "autogen/boot.c"
extern const char *raylua_boot_str;
void raylua_boot(lua_State *L, lua_CFunction loadfile)
{
lua_newtable(L);
if (loadfile) {
lua_pushstring(L, "loadfile");
lua_pushcfunction(L, loadfile);
lua_settable(L, -3);
}
lua_pushstring(L, "bind_entries");
lua_pushlightuserdata(L, raylua_entries);
lua_settable(L, -3);
lua_setglobal(L, "raylua");
if (luaL_dostring(L, raylua_boot_lua))
fputs(luaL_checkstring(L, -1), stderr);
}
/*
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <raylib.h>
#include "autogen/bind.c"
#include "autogen/boot.c"
extern const char *raylua_boot_str;
void raylua_boot(lua_State *L, lua_CFunction loadfile)
{
lua_newtable(L);
if (loadfile) {
lua_pushstring(L, "loadfile");
lua_pushcfunction(L, loadfile);
lua_settable(L, -3);
}
lua_pushstring(L, "bind_entries");
lua_pushlightuserdata(L, raylua_entries);
lua_settable(L, -3);
lua_setglobal(L, "raylua");
if (luaL_dostring(L, raylua_boot_lua))
fputs(luaL_checkstring(L, -1), stderr);
}

View File

@ -1,3 +1,19 @@
/*
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef H_RAYLUA
#define H_RAYLUA

View File

@ -1,3 +1,19 @@
--[[
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
local load = loadstring
if raylua.loadfile then

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2019 Astie Teddy
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above

View File

@ -1,112 +1,154 @@
local t = get_type(input_path)
local ffi = require "ffi"
print ">> Raylua builder <<"
ffi.cdef "typedef struct raylua_builder raylua_builder;"
local builder_new = ffi.cast("raylua_builder *(*)(const char *, const char *)", builder_new)
local builder_close = ffi.cast("void (*)(raylua_builder *)", builder_close)
local builder_add = ffi.cast("void (*)(raylua_builder *, const char *, const char *)", builder_add)
local function path_concat(...)
return table.concat({ ... }, "/")
end
if ffi.os == "Windows" and self_path:sub("-4") ~= ".exe" then
self_path = self_path .. ".exe"
end
print("Self is " .. self_path)
if t == "directory" then
local path = input_path
if ffi.os == "Windows" then
path = path .. ".exe"
else
path = path .. ".elf"
end
print("Building " .. path)
local builder = builder_new(self_path, path)
assert(builder ~= ffi.new("void *", nil), "Can't initialize builder")
local have_main = false
local function add_dir(root, dir)
for i,file in ipairs(list_dir(path_concat(root, dir))) do
if file ~= ".." then
local partial_file_path, full_file_path
if dir then
partial_file_path = path_concat(dir, file)
full_file_path = path_concat(root, dir, file)
else
partial_file_path = file
full_file_path = path_concat(root, file)
end
if partial_file_path == "main.lua" then
have_main = true
end
local t = get_type(full_file_path)
if t == "file" then
print("Adding file " .. partial_file_path)
builder_add(builder, full_file_path, partial_file_path)
elseif t == "directory" then
print("Adding directory " .. partial_file_path .. "/")
add_dir(root, partial_file_path)
else
print("Unknown file type " .. partial_file_path)
end
end
end
end
add_dir(input_path, nil)
if not have_main then
print("WARN: main.lua is missing, your executable may not run")
end
builder_close(builder)
elseif t == "file" then
local ext = input_path:sub(-4)
-- Remove extension
local path = input_path:sub(0, #input_path - 4)
if ffi.os == "Windows" then
path = path .. ".exe"
else
path = path .. ".elf"
end
print("Building " .. path)
if ext == ".zip" then
print "Build from zip file."
local dest = assert(io.open(path, "wb"), "Can't open destination file.")
local source = assert(io.open(self_path, "rb"), "Can't open self file.")
local input = assert(io.open(input_path, "rb"), "Can't open zip file.")
append_file_offset(output, source, input)
dest:close()
source:close()
input:close()
elseif ext == ".lua" then
print "Build from lua file."
local builder = builder_new(self_path, path)
builder_add(builder, input_path, "main.lua")
builder_close(builder)
end
end
print "Done"
--[[
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
--[[
Uses miniz licence :
Copyright 2013-2014 RAD Game Tools and Valve Software
Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local t = get_type(input_path)
local ffi = require "ffi"
print ">> Raylua builder <<"
ffi.cdef "typedef struct raylua_builder raylua_builder;"
local builder_new = ffi.cast("raylua_builder *(*)(const char *, const char *)", builder_new)
local builder_close = ffi.cast("void (*)(raylua_builder *)", builder_close)
local builder_add = ffi.cast("void (*)(raylua_builder *, const char *, const char *)", builder_add)
local function path_concat(...)
return table.concat({ ... }, "/")
end
if ffi.os == "Windows" and self_path:sub("-4") ~= ".exe" then
self_path = self_path .. ".exe"
end
print("Self is " .. self_path)
if t == "directory" then
local path = input_path
if ffi.os == "Windows" then
path = path .. ".exe"
else
path = path .. ".elf"
end
print("Building " .. path)
local builder = builder_new(self_path, path)
assert(builder ~= ffi.new("void *", nil), "Can't initialize builder")
local have_main = false
local function add_dir(root, dir)
for i,file in ipairs(list_dir(path_concat(root, dir))) do
if file ~= ".." then
local partial_file_path, full_file_path
if dir then
partial_file_path = path_concat(dir, file)
full_file_path = path_concat(root, dir, file)
else
partial_file_path = file
full_file_path = path_concat(root, file)
end
if partial_file_path == "main.lua" then
have_main = true
end
local t = get_type(full_file_path)
if t == "file" then
print("Adding file " .. partial_file_path)
builder_add(builder, full_file_path, partial_file_path)
elseif t == "directory" then
print("Adding directory " .. partial_file_path .. "/")
add_dir(root, partial_file_path)
else
print("Unknown file type " .. partial_file_path)
end
end
end
end
add_dir(input_path, nil)
if not have_main then
print("WARN: main.lua is missing, your executable may not run")
end
builder_close(builder)
elseif t == "file" then
local ext = input_path:sub(-4)
-- Remove extension
local path = input_path:sub(0, #input_path - 4)
if ffi.os == "Windows" then
path = path .. ".exe"
else
path = path .. ".elf"
end
print("Building " .. path)
if ext == ".zip" then
print "Build from zip file."
local dest = assert(io.open(path, "wb"), "Can't open destination file.")
local source = assert(io.open(self_path, "rb"), "Can't open self file.")
local input = assert(io.open(input_path, "rb"), "Can't open zip file.")
append_file_offset(output, source, input)
dest:close()
source:close()
input:close()
elseif ext == ".lua" then
print "Build from lua file."
local builder = builder_new(self_path, path)
builder_add(builder, input_path, "main.lua")
builder_close(builder)
end
end
print "Done"

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2019 Astie Teddy
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 Astie Teddy
Copyright (C) 2020 Astie Teddy
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above