mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 12:14:49 +02:00
Using latest love-android branch (e263d91d136d)
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
#include "config.h"
|
||||
#include "Object.h"
|
||||
|
||||
// C
|
||||
#include <stddef.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
@@ -38,7 +41,7 @@ public:
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Data() {};
|
||||
virtual ~Data() {}
|
||||
|
||||
/**
|
||||
* Gets a pointer to the data. This pointer will obviously not
|
||||
@@ -49,7 +52,7 @@ public:
|
||||
/**
|
||||
* Gets the size of the Data in bytes.
|
||||
**/
|
||||
virtual int getSize() const = 0;
|
||||
virtual size_t getSize() const = 0;
|
||||
|
||||
}; // Data
|
||||
|
||||
|
||||
@@ -38,8 +38,12 @@ void Memoizer::remove(void *key)
|
||||
|
||||
void *Memoizer::find(void *key)
|
||||
{
|
||||
if (objectMap.count(key)) return objectMap[key];
|
||||
return NULL;
|
||||
auto it = objectMap.find(key);
|
||||
|
||||
if (it != objectMap.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // love
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace love
|
||||
const char REFERENCE_TABLE_NAME[] = "love-references";
|
||||
|
||||
Reference::Reference()
|
||||
: L(0)
|
||||
: L(nullptr)
|
||||
, idx(LUA_REFNIL)
|
||||
{
|
||||
}
|
||||
@@ -64,21 +64,31 @@ void Reference::unref()
|
||||
}
|
||||
}
|
||||
|
||||
void Reference::push()
|
||||
void Reference::push(lua_State *newL)
|
||||
{
|
||||
if (idx != LUA_REFNIL)
|
||||
{
|
||||
luax_insist(L, LUA_REGISTRYINDEX, REFERENCE_TABLE_NAME);
|
||||
lua_rawgeti(L, -1, idx);
|
||||
lua_remove(L, -2);
|
||||
luax_insist(newL, LUA_REGISTRYINDEX, REFERENCE_TABLE_NAME);
|
||||
lua_rawgeti(newL, -1, idx);
|
||||
lua_remove(newL, -2);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(newL);
|
||||
}
|
||||
|
||||
lua_State *Reference::getL()
|
||||
void Reference::push()
|
||||
{
|
||||
push(L);
|
||||
}
|
||||
|
||||
lua_State *Reference::getL() const
|
||||
{
|
||||
return L;
|
||||
}
|
||||
|
||||
void Reference::setL(lua_State *newL)
|
||||
{
|
||||
L = newL;
|
||||
}
|
||||
|
||||
} // love
|
||||
|
||||
@@ -63,6 +63,14 @@ public:
|
||||
**/
|
||||
void unref();
|
||||
|
||||
/**
|
||||
* Pushes the referred value onto the stack of a different coroutine
|
||||
* in the same main Lua state.
|
||||
* THIS SHOULD NOT BE USED FOR DIFFERENT LUA STATES (created with
|
||||
* luaL_newstate)! Only with different coroutines!
|
||||
**/
|
||||
void push(lua_State *newL);
|
||||
|
||||
/**
|
||||
* Pushes the referred value onto the stack.
|
||||
**/
|
||||
@@ -72,7 +80,15 @@ public:
|
||||
* Gets the Lua state associated with this
|
||||
* reference.
|
||||
**/
|
||||
lua_State *getL();
|
||||
lua_State *getL() const;
|
||||
|
||||
/**
|
||||
* Associates a new Lua state with this reference.
|
||||
* THIS IS DANGEROUS! It is only designed to be
|
||||
* used with different coroutines from the same
|
||||
* main Lua state!
|
||||
**/
|
||||
void setL(lua_State *newL);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
namespace love
|
||||
{
|
||||
// Implementation in header.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,4 @@ char *b64_decode(const char *src, int slen, int &size);
|
||||
|
||||
} // love
|
||||
|
||||
#endif // LOVE_B64_H
|
||||
#endif // LOVE_B64_H
|
||||
|
||||
Regular → Executable
+21
@@ -45,6 +45,27 @@ std::string to_utf8(LPCWSTR wstr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring to_widestr(const std::string &str)
|
||||
{
|
||||
if (str.empty())
|
||||
return std::wstring();
|
||||
|
||||
int wide_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), nullptr, 0);
|
||||
|
||||
if (wide_size == 0)
|
||||
return std::wstring();
|
||||
|
||||
std::wstring widestr;
|
||||
widestr.resize(wide_size);
|
||||
|
||||
int ok = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), &widestr[0], widestr.length());
|
||||
|
||||
if (!ok)
|
||||
return std::wstring();
|
||||
|
||||
return widestr;
|
||||
}
|
||||
|
||||
void replace_char(std::string &str, char find, char replace)
|
||||
{
|
||||
int length = str.length();
|
||||
|
||||
Regular → Executable
+8
-1
@@ -35,6 +35,13 @@ namespace love
|
||||
**/
|
||||
std::string to_utf8(LPCWSTR wstr);
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 encoded string to a wide string.
|
||||
* @param str The UTF-8 string.
|
||||
* @return A wide string.
|
||||
**/
|
||||
std::wstring to_widestr(const std::string &str);
|
||||
|
||||
/**
|
||||
* Replace all occurences of 'find' with 'replace' in a string.
|
||||
* @param str The string to modify.
|
||||
@@ -45,4 +52,4 @@ void replace_char(std::string &str, char find, char replace);
|
||||
|
||||
} // love
|
||||
|
||||
#endif // LOVE_WINDOWS
|
||||
#endif // LOVE_WINDOWS
|
||||
|
||||
@@ -31,7 +31,7 @@ Data *luax_checkdata(lua_State *L, int idx)
|
||||
int w_Data_getString(lua_State *L)
|
||||
{
|
||||
Data *t = luax_checkdata(L, 1);
|
||||
lua_pushlstring(L, (const char *) t->getData(), (size_t) t->getSize());
|
||||
lua_pushlstring(L, (const char *) t->getData(), t->getSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ int w_Data_getPointer(lua_State *L)
|
||||
int w_Data_getSize(lua_State *L)
|
||||
{
|
||||
Data *t = luax_checkdata(L, 1);
|
||||
lua_pushinteger(L, t->getSize());
|
||||
lua_pushnumber(L, (lua_Number) t->getSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user