From ff1ceba0bc21aa5bba6b6ffe65002a9ebec16833 Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Thu, 27 Feb 2020 18:38:21 +0100 Subject: [PATCH] README and licence stuff --- README.md | 59 ++++++++- assets/logo.png | Bin 0 -> 2532 bytes makefile | 4 +- src/raylib.lua | 16 +++ src/raylua.c | 78 +++++++----- src/raylua.h | 16 +++ src/raylua.lua | 16 +++ src/raylua_builder.c | 2 +- src/raylua_builder.lua | 266 ++++++++++++++++++++++++----------------- src/raylua_e.c | 2 +- src/raylua_s.c | 2 +- 11 files changed, 312 insertions(+), 149 deletions(-) create mode 100644 assets/logo.png diff --git a/README.md b/README.md index 9e9e248..433cadb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..a8bedc4f0fc14061ca0e7fa98e25f3ac7baefe4e GIT binary patch literal 2532 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911L)MWvCLlCbx$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&eBK4*bPWHAE+-(e7DJf6QI1t?bO>Eakt5%+eo;W}qeK4$S5-RGC8$Fo;) zGJldTVm8~&HFc$Gbj73p|9(D?Ka#D=P_dPTVf{3Q2Ump{_Czr?gnKi5$l_#((`7uc z8mHvj+l)W>A9PPF?iFHK;dIW_i(vtm<#i3l2CXMCi&+>}O&FCJ4U*BsK<#WGaqriK ze;e1!xz<^EF(g#HcK&^QUzNzum%xnoa4r8^`QNVspDYLFzqajmTk7AecAq%EPly3k z(~k%3{~oL;hsfCdSZHtYDi)%LzwQNpUzIq-v}XBV&5Q3r>_KRWlVym^ee6>+;nlI3 zKOU@>yZ?H1Q@zgBUgMAFJ*uZL)Br^lK)i$Dw)?J!v;L1*C7u3g{={z@j6ZseKRSYV z&Fiab*01OKw=u;0+!1@_w}DI_B!QwJ9((-PA93-bf09?`&FQRnyS13*fiX}N#N*%h z>f_#hT0f2l-L(+@-?PP?^T74B&;Cz^8MeO4Y_I+jTQ7!vd8Yr@*Ia#ET^stLzxL|p zm$ix@D@s@YtbYo1@0->0eBX0t_6s$vk3Rcf8)j+z*PN<&urKar{fqy(>iG9xs~*Vz zUX_0Nw-d-IC$fwxfnNU*+W-D*=t28$q34%E(0Yt$wq2L#+rGLgB)H-QeqbkyvVz>tQ7HnIh`eZK95h1tGW zH^1zg0E`5SO}ElE0bP&j1GCAs>oLL-<{EGW1c^SscsLp!)iRO3YWcu;0mX;>60LKK z+qc8x+G5izpL-zTU4?3P9-(vG`SU|zkzJ5tI&%+5xD=F(R$27R-CG5ZZD3tQQe~LC zI<~v!vIgUen72_+X1jq>0VoVX$rx-LB&eqX^9jfqpeP5$2q?66PXM|3L>4gO!ht~s zaS9}Uy?}x8#tGyD<<+@r`Bk>h)#~{{E(J+fUVd$9{<9jcdv@IUohR=%!wkRorRtpT zKRJ+BKz4sxcD*?7({}}HnmFxu94KYhvx0)OZ_T!uZ>m9A?XM`zc2FV%W{+^VV?k+j z_PuyVnBR~Mu!9vSprQj3P1F;rDrH!}Pi)I%pDe=>H9}1vtnDK4-{<%LXMb?@ka4@j Sf%(9e8H1;*pUXO@geCy1tyoV0 literal 0 HcmV?d00001 diff --git a/makefile b/makefile index ea4b931..f04b38e 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/src/raylib.lua b/src/raylib.lua index a0888e4..ef6bd83 100644 --- a/src/raylib.lua +++ b/src/raylib.lua @@ -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" diff --git a/src/raylua.c b/src/raylua.c index 63922ad..7cb687e 100644 --- a/src/raylua.c +++ b/src/raylua.c @@ -1,31 +1,47 @@ -#include -#include -#include - -#include -#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 +#include +#include + +#include +#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); +} diff --git a/src/raylua.h b/src/raylua.h index e8a7ca5..4acb443 100644 --- a/src/raylua.h +++ b/src/raylua.h @@ -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 diff --git a/src/raylua.lua b/src/raylua.lua index f498a96..b3f0df6 100644 --- a/src/raylua.lua +++ b/src/raylua.lua @@ -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 diff --git a/src/raylua_builder.c b/src/raylua_builder.c index eceaa7c..41b6183 100644 --- a/src/raylua_builder.c +++ b/src/raylua_builder.c @@ -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 diff --git a/src/raylua_builder.lua b/src/raylua_builder.lua index 3af75fd..a8bc258 100644 --- a/src/raylua_builder.lua +++ b/src/raylua_builder.lua @@ -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" diff --git a/src/raylua_e.c b/src/raylua_e.c index d7c1a5d..6ae312b 100644 --- a/src/raylua_e.c +++ b/src/raylua_e.c @@ -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 diff --git a/src/raylua_s.c b/src/raylua_s.c index d3219ff..2b7a9ed 100644 --- a/src/raylua_s.c +++ b/src/raylua_s.c @@ -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