Skip to content

Commit

Permalink
luasocket + add callback check for keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Aug 11, 2024
1 parent 55f91c5 commit d842bf4
Show file tree
Hide file tree
Showing 74 changed files with 16,753 additions and 29 deletions.
49 changes: 48 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
set(APP_TITLE "LÖVE Potion")
set(APP_AUTHOR "LÖVEBrew Team")

file(COPY libraries/luasocket DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(APP_TITLE "LÖVE Potion (${COMMIT_HASH})")
target_compile_definitions(${PROJECT_NAME} PRIVATE __DEBUG__=1)
Expand Down Expand Up @@ -79,6 +81,8 @@ if(NINTENDO_3DS)
target_sources(${PROJECT_NAME} PRIVATE
source/modules/image/magpie/T3XHandler.cpp
)

execute_process(COMMAND patch -d ${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket -N -i ${PROJECT_SOURCE_DIR}/platform/ctr/libraries/luasocket.patch)
endif()

if (NINTENDO_SWITCH)
Expand Down Expand Up @@ -212,6 +216,47 @@ add_library(lua53
)
target_link_libraries(lua53 PRIVATE PkgConfig::lua51)

add_library(luasocket
${CMAKE_CURRENT_BINARY_DIR}/luasocket/luasocket.hpp
${CMAKE_CURRENT_BINARY_DIR}/luasocket/luasocket.cpp
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/auxiliar.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/auxiliar.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/buffer.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/buffer.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/compat.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/compat.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/except.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/except.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/inet.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/inet.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/io.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/io.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/ltn12.lua
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/luasocket.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/luasocket.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/mime.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/mime.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/options.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/options.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/pierror.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/select.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/select.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/smtp.lua
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/socket.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/tcp.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/tcp.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/timeout.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/timeout.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/udp.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/udp.h
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/usocket.c
${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket/usocket.h
)
target_link_libraries(luasocket PRIVATE PkgConfig::lua51)
target_include_directories(luasocket PRIVATE
libraries/lua53
)

FetchContent_Declare(lua-https
GIT_REPOSITORY https://github.com/love2d/lua-https
GIT_TAG main
Expand Down Expand Up @@ -323,7 +368,7 @@ endif()

# link everything else
target_link_libraries(${PROJECT_NAME} PRIVATE
${APP_LIBS} z luabit lua53 ogg modplug lua-https
${APP_LIBS} z luabit lua53 ogg modplug lua-https luasocket
)


Expand All @@ -333,6 +378,7 @@ include_directories(
libraries/dr
libraries/lua53
libraries/noise1234
libraries/luasocket
libraries/physfs
libraries/wuff
libraries/utf8
Expand All @@ -351,6 +397,7 @@ source/common/Message.cpp
source/common/Module.cpp
source/common/Object.cpp
source/common/pixelformat.cpp
source/common/Reference.cpp
source/common/Stream.cpp
source/common/types.cpp
source/common/Variant.cpp
Expand Down
82 changes: 82 additions & 0 deletions include/common/Reference.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (c) 2006-2024 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/

#ifndef LOVE_REFERENCE_H
#define LOVE_REFERENCE_H

struct lua_State;

namespace love
{

/**
* This class wraps the reference functionality built into
* Lua, which allows C++ code to refer to Lua variables.
**/
class Reference
{
public:
/**
* Creates the reference object, but does not create
* the actual reference.
**/
Reference();

/**
* Creates the object and a reference to the value
* on the top of the stack.
**/
Reference(lua_State* L);

/**
* Deletes the reference, if any.
**/
virtual ~Reference();

/**
* Creates a reference to the value on the
* top of the stack.
**/
void ref(lua_State* L);

/**
* Unrefs the reference, if any.
**/
void unref();

/**
* Pushes the referred value onto the stack of the specified Lua coroutine.
* NOTE: The coroutine *must* belong to the same Lua state that was used for
* Reference::ref.
**/
void push(lua_State* L);

private:
// A pinned coroutine (probably the main thread) belonging to the Lua state
// in which the reference resides.
lua_State* pinnedL;

// Index to the Lua reference.
int idx;
};

} // namespace love

#endif // LOVE_REFERENCE_H
2 changes: 2 additions & 0 deletions include/common/luax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ namespace love

lua_Number luax_checknumberclamped01(lua_State* L, int index);

Reference* luax_refif(lua_State* L, int type);

// #endregion

// #region Registry
Expand Down
52 changes: 42 additions & 10 deletions include/modules/keyboard/Keyboard.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,39 @@
#include "common/Result.hpp"

#include <memory>
#include <string_view>

namespace love
{
class KeyboardBase : public Module
{
public:
enum KeyboardResult
{
RESULT_OK, //< Input accepted
RESULT_CANCEL, //< Input cancelled
RESULT_CONTINUE, //< Input validation callback should continue
RESULT_MAX_ENUM
};

struct KeyboardValidationInfo;

#if defined(__3DS__)
using ValidationError = const char**;
#elif defined(__SWITCH__)
using ValidationError = char*;
#endif

typedef KeyboardResult (*KeyboardValidationCallback)(const KeyboardValidationInfo* info,
const char* text, ValidationError error);

struct KeyboardValidationInfo
{
KeyboardValidationCallback callback = nullptr;
void* data = nullptr;
void* luaState = nullptr;
};

enum KeyboardType
{
TYPE_NORMAL,
Expand All @@ -20,10 +47,11 @@ namespace love

struct KeyboardOptions
{
uint8_t type;
bool password;
std::string_view hint;
uint32_t maxLength;
uint8_t type; // KeyboardType
bool password; // Whether the input should be hidden
std::string_view hint; // Hint text
uint32_t maxLength; // Maximum length of the input
KeyboardValidationInfo callback; // Callback function
};

enum KeyboardOption
Expand All @@ -32,6 +60,7 @@ namespace love
OPTION_PASSCODE,
OPTION_HINT,
OPTION_MAX_LENGTH,
OPTION_CALLBACK,
OPTION_MAX_ENUM
};

Expand All @@ -46,11 +75,7 @@ namespace love
static constexpr uint32_t MULTIPLIER = 3;
#endif

KeyboardBase() :
Module(M_KEYBOARD, "love.keyboard"),
keyRepeat(false),
showing(false),
text(nullptr)
KeyboardBase() : Module(M_KEYBOARD, "love.keyboard"), keyRepeat(false), showing(false), text(nullptr)
{}

virtual ~KeyboardBase()
Expand Down Expand Up @@ -86,14 +111,21 @@ namespace love
{ "type", OPTION_TYPE },
{ "password", OPTION_PASSCODE },
{ "hint", OPTION_HINT },
{ "maxLength", OPTION_MAX_LENGTH }
{ "maxLength", OPTION_MAX_LENGTH },
{ "callback", OPTION_CALLBACK }
);

STRINGMAP_DECLARE(KeyboardTypes, KeyboardType,
{ "normal", TYPE_NORMAL },
{ "qwerty", TYPE_QWERTY },
{ "numpad", TYPE_NUMPAD }
);

STRINGMAP_DECLARE(KeyboardResults, KeyboardResult,
{ "ok", RESULT_OK },
{ "cancel", RESULT_CANCEL },
{ "continue", RESULT_CONTINUE }
);
// clang-format on

protected:
Expand Down
Loading

0 comments on commit d842bf4

Please sign in to comment.