Skip to content

Commit

Permalink
0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
well-in-that-case authored Jan 23, 2023
2 parents 3b7cc67 + 5df7b97 commit c986fb6
Show file tree
Hide file tree
Showing 34 changed files with 997 additions and 356 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pluto linguist-language=Lua
6 changes: 3 additions & 3 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
src/plutoc
src/libpluto.dll
src/libpluto.a
- run: src/pluto tests/basic.lua
- run: src/pluto tests/basic.pluto
macos-pluto:
runs-on: macos-latest
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
src/plutoc
src/libpluto.dll
src/libpluto.a
- run: src/pluto tests/basic.lua
- run: src/pluto tests/basic.pluto
windows-pluto:
runs-on: windows-latest
steps:
Expand All @@ -49,4 +49,4 @@ jobs:
src/plutoc.exe
src/libpluto.dll
src/libpluto.a
- run: src/pluto.exe tests/basic.lua
- run: src/pluto.exe tests/basic.pluto
7 changes: 7 additions & 0 deletions Pluto.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>..\Soup\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -142,6 +143,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>..\Soup\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -153,6 +155,9 @@
<ItemGroup>
<ClCompile Include="src\lapi.cpp" />
<ClCompile Include="src\lauxlib.cpp" />
<ClCompile Include="src\lbase32.cpp" />
<ClCompile Include="src\lbase58.cpp" />
<ClCompile Include="src\lbase64.cpp" />
<ClCompile Include="src\lbaselib.cpp" />
<ClCompile Include="src\lcode.cpp" />
<ClCompile Include="src\lcorolib.cpp" />
Expand All @@ -166,6 +171,7 @@
<ClCompile Include="src\lgc.cpp" />
<ClCompile Include="src\linit.cpp" />
<ClCompile Include="src\liolib.cpp" />
<ClCompile Include="src\ljson.cpp" />
<ClCompile Include="src\llex.cpp" />
<ClCompile Include="src\lmathlib.cpp" />
<ClCompile Include="src\lmem.cpp" />
Expand Down Expand Up @@ -197,6 +203,7 @@
<ClInclude Include="src\ldo.h" />
<ClInclude Include="src\lfunc.h" />
<ClInclude Include="src\lgc.h" />
<ClInclude Include="src\ljson.hpp" />
<ClInclude Include="src\ljumptab.h" />
<ClInclude Include="src\ljumptabgcc.h" />
<ClInclude Include="src\llex.h" />
Expand Down
3 changes: 3 additions & 0 deletions Pluto.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ClCompile Include="src\ltable.cpp" />
<ClCompile Include="src\ltablib.cpp" />
<ClCompile Include="src\lcryptolib.cpp" />
<ClCompile Include="src\lbase64.cpp" />
<ClCompile Include="src\lbase58.cpp" />
<ClCompile Include="src\lbase32.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\ltm.h" />
Expand Down
1 change: 1 addition & 0 deletions src/.sun
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require ../../Soup/soup include_dir=../../Soup
+*.cpp
-lua.cpp
-luac.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/ErrorMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "llex.h"

namespace Pluto // Decided to create the first instance of 'namespace' in this project. Figuring I'll put Pluto-related utility in here for now.
namespace Pluto
{
class ErrorMessage
{
Expand Down
4 changes: 4 additions & 0 deletions src/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
return s;
}

LUA_API const char* lua_pushstring(lua_State* L, const std::string& str) {
return lua_pushstring(L, str.c_str());
}


LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
va_list argp) {
Expand Down
9 changes: 9 additions & 0 deletions src/lauxlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,18 @@ static int skipcomment (FILE *f, int *cp) {
else return 0; /* no comment */
}

#ifdef PLUTO_LOADFILE_HOOK
extern "C" bool PLUTO_LOADFILE_HOOK(const char* filename);
#endif

LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
const char *mode) {
#ifdef PLUTO_LOADFILE_HOOK
if (!PLUTO_LOADFILE_HOOK(filename)) {
lua_pushfstring(L, "%s failed content moderation policy", filename);
return LUA_ERRFILE;
}
#endif
LoadF lf;
int status, readstatus;
int c;
Expand Down
29 changes: 29 additions & 0 deletions src/lbase32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "lauxlib.h"
#include "lualib.h"

#ifdef PLUTO_USE_SOUP

#include <soup/base32.hpp>

static int encode(lua_State* L) {
lua_pushstring(L, soup::base32::encode(luaL_checkstring(L, 1), (bool)lua_toboolean(L, 2)).c_str());
return 1;
}

static int decode(lua_State* L) {
lua_pushstring(L, soup::base32::decode(luaL_checkstring(L, 1)).c_str());
return 1;
}

static const luaL_Reg funcs[] = {
{"encode", encode},
{"decode", decode},
{nullptr, nullptr}
};

LUAMOD_API int luaopen_base32(lua_State* L) {
luaL_newlib(L, funcs);
return 1;
}

#endif
41 changes: 41 additions & 0 deletions src/lbase58.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "lauxlib.h"
#include "lualib.h"

#ifdef PLUTO_USE_SOUP

#include <soup/string.hpp>
#include <soup/base58.hpp>

static int decode(lua_State* L) {
try {
lua_pushstring(L, soup::string::bin2hex(soup::base58::decode(luaL_checkstring(L, 1))).c_str());
}
catch (...) {
luaL_error(L, "Attempted to decode non-base58 string.");
}
return 1;
}

static int is_valid(lua_State* L) {
try {
const auto discarding = soup::base58::decode(luaL_checkstring(L, 1));
lua_pushboolean(L, true);
}
catch (...) {
lua_pushboolean(L, false);
}
return 1;
}

static const luaL_Reg funcs[] = {
{"is_valid", is_valid},
{"decode", decode},
{nullptr, nullptr}
};

LUAMOD_API int luaopen_base58(lua_State* L) {
luaL_newlib(L, funcs);
return 1;
}

#endif
42 changes: 42 additions & 0 deletions src/lbase64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "lauxlib.h"
#include "lualib.h"

#ifdef PLUTO_USE_SOUP

#include <string>
#include <soup/base64.hpp>

static int encode(lua_State* L) {
lua_pushstring(L, soup::base64::encode(luaL_checkstring(L, 1), (bool)lua_toboolean(L, 2)).c_str());
return 1;
}

static int decode(lua_State* L) {
lua_pushstring(L, soup::base64::decode(luaL_checkstring(L, 1)).c_str());
return 1;
}

static int urlEncode(lua_State* L) {
lua_pushstring(L, soup::base64::urlEncode(luaL_checkstring(L, 1), (bool)lua_toboolean(L, 2)).c_str());
return 1;
}

static int urlDecode(lua_State* L) {
lua_pushstring(L, soup::base64::urlDecode(luaL_checkstring(L, 1)).c_str());
return 1;
}

static const luaL_Reg funcs[] = {
{"url_encode", urlEncode},
{"url_decode", urlDecode},
{"encode", encode},
{"decode", decode},
{nullptr, nullptr}
};

LUAMOD_API int luaopen_base64(lua_State* L) {
luaL_newlib(L, funcs);
return 1;
}

#endif
19 changes: 7 additions & 12 deletions src/lbaselib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,7 @@ static int luaB_newuserdata (lua_State *L) {
}


/*
0.4.0 Changes:
- Deprecated in favor of os.sleep. Will be removed in 0.5.0.
*/
static int luaB_sleep (lua_State *L) {
std::chrono::milliseconds timespan(luaL_checkinteger(L, 1));
std::this_thread::sleep_for(timespan);
return 0;
}


static const luaL_Reg base_funcs[] = {
{"sleep", luaB_sleep},
{"newuserdata", luaB_newuserdata},
{"assert", luaB_assert},
{"collectgarbage", luaB_collectgarbage},
Expand Down Expand Up @@ -576,6 +564,13 @@ LUAMOD_API int luaopen_base (lua_State *L) {
/* set global _PVERSION */
lua_pushliteral(L, PLUTO_VERSION);
lua_setfield(L, -2, "_PVERSION");
/* set global _PSOUP */
#ifdef PLUTO_USE_SOUP
lua_pushboolean(L, true);
#else
lua_pushboolean(L, false);
#endif
lua_setfield(L, -2, "_PSOUP");
return 1;
}

5 changes: 4 additions & 1 deletion src/ldo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,14 @@ static void f_parser (lua_State *L, void *ud) {
LClosure *cl;
struct SParser *p = cast(struct SParser *, ud);
int c = zgetc(p->z); /* read first character */
#ifndef PLUTO_DISABLE_COMPILED
if (c == LUA_SIGNATURE[0]) {
checkmode(L, p->mode, "binary");
cl = luaU_undump(L, p->z, p->name);
}
else {
else
#endif
{
checkmode(L, p->mode, "text");
cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
}
Expand Down
6 changes: 6 additions & 0 deletions src/linit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ static const luaL_Reg loadedlibs[] = {


static const luaL_Reg preloadedLibs[] = {
#ifdef PLUTO_USE_SOUP
{"json", luaopen_json},
{"base32", luaopen_base32},
{"base58", luaopen_base58},
{"base64", luaopen_base64},
#endif
{"crypto", luaopen_crypto},
{NULL, NULL}
};
Expand Down
12 changes: 12 additions & 0 deletions src/liolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,17 @@ static int makedir (lua_State *L)
}


static int makedirs (lua_State *L)
{
Protect(
const auto path = getStringStreamPath(L);
lua_pushboolean(L, std::filesystem::create_directories(path))
);

return 1;
}


/*
0.4.0 Changes:
- Second boolean parameter will toggle recursive iteration.
Expand Down Expand Up @@ -978,6 +989,7 @@ static const luaL_Reg iolib[] = {
{"remove", l_remove},
{"listdir", listdir},
{"makedir", makedir},
{"makedirs", makedirs},
{"absolute", absolute},
{"copyto", copyto},
{"exists", exists},
Expand Down
39 changes: 39 additions & 0 deletions src/ljson.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "lauxlib.h"
#include "lualib.h"

#ifdef PLUTO_USE_SOUP

#include "ljson.hpp"

static int encode(lua_State* L) {
auto root = checkJson(L, 1);
if (lua_gettop(L) >= 2 && lua_toboolean(L, 2))
{
lua_pushstring(L, root->encodePretty());
}
else
{
lua_pushstring(L, root->encode());
}
return 1;
}

static int decode(lua_State* L)
{
auto root = soup::json::decodeForDedicatedVariable(luaL_checkstring(L, 1));
pushFromJson(L, *root);
return 1;
}

static const luaL_Reg funcs[] = {
{"encode", encode},
{"decode", decode},
{nullptr, nullptr}
};

LUA_API int luaopen_json(lua_State *L) {
luaL_newlib(L, funcs);
return 1;
}

#endif
Loading

0 comments on commit c986fb6

Please sign in to comment.