Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PushCClosure(const void* func, DWORD n) {
- try {
- r_lua_pushcclosure(RLS, (int)func, n);
- }
- catch (...) {};
- }
- void rlua_pushobject(DWORD pRobloxState, TValue* value) {
- auto& topa = *(TValue * *)(pRobloxState + top);
- *topa = *value;
- ++topa;
- }
- int Debug_GetMetaTable(lua_State* L) {
- if (lua_gettop(L) == 0) {
- luaL_error(L, "'debug.getrawmetatable' needs 1 argument.");
- return 0;
- }
- Wrap(RLS, L, 1);
- if (r_lua_getmetatable(RLS, -1) == 0) {
- lua_pushnil(L);
- return 0;
- }
- UnWrap(L, RLS, -1);
- return 1;
- }
- int Debug_GetRegistry(lua_State* L) {
- r_lua_pushvalue(RLS, LUA_REGISTRYINDEX);
- return 1;
- }
- static int Debug_setfenv(lua_State* L) {
- luaL_checktype(L, 2, LUA_TTABLE);
- lua_settop(L, 2);
- if (lua_setfenv(L, 1) == 0)
- luaL_error(L, LUA_QL("setfenv")
- " cannot change environment of given object");
- return 1;
- }
- static int auxupvalue(lua_State* L, int get) {
- const char* name;
- int n = luaL_checkint(L, 2);
- luaL_checktype(L, 1, LUA_TFUNCTION);
- if (lua_iscfunction(L, 1)) return 0;
- name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
- if (name == NULL) return 0;
- lua_pushstring(L, name);
- lua_insert(L, -(get + 1));
- return get + 1;
- }
- static int Debug_getupvalue(lua_State* L) {
- return auxupvalue(L, 1);
- }
- static int Debug_setupvalue(lua_State* L) {
- luaL_checkany(L, 3);
- return auxupvalue(L, 0);
- }
- static int custom_checkcaller(lua_State* L) {
- r_lua_pushboolean(RLS, true);
- return 1;
- }
- int CrashRoblox(lua_State* L) {
- exit(10);
- return 0;
- }
- static lua_State* getthread(lua_State* L, int* arg) {
- if (lua_isthread(L, 1)) {
- *arg = 1;
- return lua_tothread(L, 1);
- }
- else {
- *arg = 0;
- return L;
- }
- }
- int setreadonly(lua_State* L) {
- DWORD index2address = (DWORD)r_lua_index2(RLS, -1);
- *(BYTE*)(*(DWORD*)index2address + 10) = lua_toboolean(L, -1);
- return 0;
- }
- int metatable_handler(lua_State* L)
- {
- UnWrap(L, RLS, lua_upvalueindex(1));
- const char* key = lua_tostring(L, 2);
- r_lua_getmetatable(RLS, -1);
- r_lua_setreadonly(RLS, -1, 0);
- UnWrap(L, RLS, 3);
- r_lua_setfield(RLS, -2, key);
- r_lua_pop(RLS, 2);
- return 0;
- }
- int getRawMetaTable(lua_State* L)
- {
- UnWrap(L, RLS, 1);
- r_lua_getmetatable(RLS, -1);
- r_lua_setreadonly(RLS, -1, 0);
- Wrap(RLS, L, -1);
- lua_newtable(L);
- {
- lua_pushvalue(L, 1);
- lua_pushcclosure(L, metatable_handler, 1);
- lua_setfield(L, -2, "__newindex");
- }
- lua_setmetatable(L, -2);
- return 1;
- }
- int getgenv(lua_State* L) {
- lua_pushvalue(L, LUA_GLOBALSINDEX);
- Wrap(RLS, L, -1);
- return 1;
- }
- int getreg(lua_State* L) {
- lua_pushvalue(L, LUA_REGISTRYINDEX);
- Wrap(RLS, L, -1);
- return 1;
- }
- int getrenv(lua_State* L) {
- lua_pushvalue(L, int(RLS));
- Wrap(RLS, L, -1);
- return 1;
- }
- static int loadstring(lua_State* L) {
- size_t l;
- const char* s = luaL_checklstring(L, 1, &l);
- const char* chunkname = luaL_optstring(L, 2, s);
- return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
- }
- void lua_setfield(DWORD L, int idx, const char* k) {
- r_lua_pushvalue(L, idx);
- if (r_lua_getmetatable(L, -1)) {
- r_lua_getfield(L, -1, "__newindex");
- r_lua_pushvalue(L, -3);
- r_lua_pushstring(L, k);
- r_lua_pushvalue(L, -6);
- r_lua_pop(L, 3);
- }
- else {
- std::cout << "0\n";
- r_lua_pop(L, 1);
- lua_setfield(L, idx, k);
- }
- }
- r_TValue* r_gettop(int rlua_State) {
- return *(r_TValue * *)(rlua_State + 16);
- }
- int setrawmetatable_impl(lua_State* rlua_State) {
- if (r_lua_gettop(RLS) < 2) {
- r_lua_pushboolean(RLS, 0);
- r_lua_pushstring(RLS, "2 or more arguments expected");
- return 2;
- }
- r_TValue* top = r_gettop(RLS);
- r_TValue* obj1 = top - 1;
- r_TValue* obj0 = top - 2;
- if (!(obj0->tt == R_LUA_TTABLE || obj0->tt == R_LUA_TUSERDATA) || !(obj1->tt == R_LUA_TNIL || obj1->tt == R_LUA_TTABLE)) {
- r_lua_pushboolean(RLS, 0);
- r_lua_pushstring(RLS, "bad argument types");
- return 2;
- }
- r_lua_setmetatable(RLS, 1);
- r_lua_pushboolean(RLS, 1);
- return 1;
- }
- static int GC(lua_State* Thread) {
- void* UD = lua_touserdata(Thread, 1);
- if (RLS) {
- r_lua_rawgeti(RLS, LUA_REGISTRYINDEX, (int)UD);
- if (r_lua_type(RLS, -1) <= R_LUA_TNIL) {
- lua_pushnil(Thread);
- lua_rawseti(Thread, LUA_REGISTRYINDEX, (int)UD);
- }
- }
- return 0;
- }
- int getupvalues(lua_State* L)
- {
- lua_pushvalue(L, 1);
- lua_newtable(L);
- int idx = 1;
- while (true)
- {
- const char* name = lua_getupvalue(L, -2, idx);
- if (!name)
- {
- break;
- }
- lua_setfield(L, -2, name);
- idx++;
- }
- return 1;
- }
- int error(lua_State* thread) {
- std::string errorstr = lua_tostring(thread, -1);
- int type = lua_tonumber(thread, -2);
- std::string finalerror = "error('"; finalerror = finalerror + errorstr; finalerror = finalerror + "')";
- luaL_dostring(thread, finalerror.c_str());
- return 1;
- }
- int newcclosure(lua_State* L) {
- lua_pushvalue(L, 1);
- return 1;
- }
- int getsenv(lua_State* LS) {
- lua_pushvalue(LS, LUA_ENVIRONINDEX);
- Wrap(RLS, LS, -1);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement