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 %.o: %.c
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)
all: luajit raylib raylua_s raylua_e all: raylua_s raylua_e luajit raylib
luajit: luajit:
$(MAKE) -C luajit amalg BUILDMODE=static $(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 raylua_e: src/raylua.o src/raylua_e.o src/raylua_builder.o src/lib/miniz.o
$(CC) -o $@ $^ $(LDFLAGS) $(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 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" print "[RAYLUA] Raylua boot script"
local ffi = require "ffi" local ffi = require "ffi"

View File

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