Skip to content

Commit

Permalink
revert lightuserinteger implementation. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Aug 14, 2024
1 parent 46763d2 commit 17802e4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
34 changes: 34 additions & 0 deletions Source/3rdParty/Lua/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) {
}


LUA_API lua_Integer lua_tolightuserinteger (lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
switch (ttype(o)) {
case LUA_TLIGHTUSERDATA: return check_exp(ttislightuserdata(o), val_(o).i);
default: return 0;
}
}


LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
return (!ttisthread(o)) ? NULL : thvalue(o);
Expand Down Expand Up @@ -651,6 +660,14 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
}


LUA_API void lua_pushlightuserinteger (lua_State *L, lua_Integer n) {
lua_lock(L);
{ TValue* io = s2v(L->top.p); val_(io).i = n; settt_(io, LUA_VLIGHTUSERDATA); }
api_incr_top(L);
lua_unlock(L);
}


LUA_API int lua_pushthread (lua_State *L) {
lua_lock(L);
setthvalue(L, s2v(L->top.p), L);
Expand Down Expand Up @@ -997,6 +1014,23 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
}


LUA_API int lua_setlightusermetatable (lua_State *L) {
Table *mt;
lua_lock(L);
api_checknelems(L, 1);
if (ttisnil(s2v(L->top.p - 1)))
mt = NULL;
else {
api_check(L, ttistable(s2v(L->top - 1)), "table expected");
mt = hvalue(s2v(L->top.p - 1));
}
G(L)->mt[LUA_TLIGHTUSERDATA] = mt;
L->top.p--;
lua_unlock(L);
return 1;
}


LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
TValue *o;
int res;
Expand Down
3 changes: 3 additions & 0 deletions Source/3rdParty/Lua/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_Integer (lua_tolightuserinteger) (lua_State* L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);

Expand Down Expand Up @@ -253,6 +254,7 @@ LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API void (lua_pushlightuserinteger) (lua_State* L, lua_Integer n);
LUA_API int (lua_pushthread) (lua_State *L);


Expand Down Expand Up @@ -284,6 +286,7 @@ LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API int (lua_setlightusermetatable) (lua_State *L);
LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);


Expand Down
2 changes: 1 addition & 1 deletion Source/Basic/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <thread>

#define DORA_VERSION "1.5.10"_slice
#define DORA_REVISION "3"_slice
#define DORA_REVISION "4"_slice

#if BX_PLATFORM_ANDROID
#include <jni.h>
Expand Down
3 changes: 0 additions & 3 deletions Source/Lua/ToLua/tolua++.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,10 @@ Slice tolua_tofieldslice(lua_State* L, int lo, int index, const char* def);

union LightValue {
using ValueType = Vec2;
void* p;
lua_Integer i;
ValueType value;
explicit LightValue(lua_Integer v)
: i(v) { }
explicit LightValue(void* v)
: p(v) { }
LightValue(const ValueType& v)
: value(v) { }
operator ValueType() const { return value; }
Expand Down
18 changes: 8 additions & 10 deletions Source/Lua/ToLua/tolua_fix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,47 +215,45 @@ Slice tolua_tofieldslice(lua_State* L, int lo, int index, const char* def) {
}

void tolua_pushlight(lua_State* L, LightValue var) {
lua_pushlightuserdata(L, var.p);
lua_pushlightuserinteger(L, var.i);
}

void tolua_setlightmetatable(lua_State* L) {
lua_rawgeti(L, LUA_REGISTRYINDEX, LuaType<LightValue::ValueType>()); // mt
if (lua_isnil(L, -1)) { // mt == nil
if (lua_isnil(L, -1)) // mt == nil
{
Error("[Lua] Type of light value is not registered!");
lua_pop(L, 1);
lua_pushnil(L);
return;
}
lua_pushlightuserdata(L, nullptr); // mt lud
lua_insert(L, -2); // lud mt
lua_setmetatable(L, -2); // lud[mt] = mt, lud
lua_pop(L, 1); // empty
lua_setlightusermetatable(L);
}

LightValue tolua_tolight(lua_State* L, int narg, LightValue def) {
if (lua_gettop(L) < abs(narg)) {
return def;
} else {
return LightValue(lua_touserdata(L, narg));
return LightValue(lua_tolightuserinteger(L, narg));
}
}

LightValue tolua_tolight(lua_State* L, int narg) {
return LightValue(lua_touserdata(L, narg));
return LightValue(lua_tolightuserinteger(L, narg));
}

LightValue tolua_tofieldlight(lua_State* L, int lo, int index, LightValue def) {
lua_pushnumber(L, index);
lua_gettable(L, lo);
LightValue v = lua_isnil(L, -1) ? def : LightValue(lua_touserdata(L, -1));
LightValue v = lua_isnil(L, -1) ? def : LightValue(lua_tolightuserinteger(L, -1));
lua_pop(L, 1);
return v;
}

LightValue tolua_tofieldlight(lua_State* L, int lo, int index) {
lua_pushnumber(L, index);
lua_gettable(L, lo);
LightValue v = LightValue(lua_touserdata(L, -1));
LightValue v = LightValue(lua_tolightuserinteger(L, -1));
lua_pop(L, 1);
return v;
}
Expand Down

0 comments on commit 17802e4

Please sign in to comment.