Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
💀
Browse files Browse the repository at this point in the history
  • Loading branch information
RadiantUwU committed Oct 30, 2023
1 parent bb0a50c commit 3c45d1d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/classes/rblx_basic_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ struct LuaString {
bool operator==(std::nullptr_t) {
return s == nullptr;
}
bool operator==(const char* s) {
return strcmp(s, this->s) == 0;
}
bool operator==(const LuaString& o) {
return o.l==l and memcmp(o.s, s, l);
}
bool operator==(const LuaString&& o) {
return o.l==l and memcmp(o.s, s, l);
}
};

struct Axes {
Expand Down
1 change: 1 addition & 0 deletions src/classes/rblx_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Instance {
RBXScriptSignal *DescendantRemoving;
RBXScriptSignal *Destroying;

static int new_instance(lua_State *L);
};

}
Expand Down
23 changes: 23 additions & 0 deletions src/classes/rblx_instance_new_implementation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "rblx_instance.hpp"
#include "rblx_main.hpp"
#include "rblx_basic_types.hpp"
#include <lua.h>

namespace godot {

int Instance::new_instance(lua_State *L) {
luau_function_context fn = L;
fn.assert_type_argument(1,"ClassName",LUA_TSTRING);
RBXVariant v_temp = fn.as_object(1);
LuaString s = LuaString(v.get_str(),v.get_slen());
RobloxVMInstance *vm;
fn.rawget(LUA_REGISTRYINDEX,"ROBLOX_VM");
v_temp = fn.to_object();
vm = (RobloxVMInstance*)(void*)v_temp;
if (s == "Instance") {// TODO: illegal on roblox lmaooo
fn.new_instance<Instance>(vm);
return 1;
}
}

}
13 changes: 11 additions & 2 deletions src/classes/rblx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ RBXVariant luau_context::to_object(int idx) {

void RobloxVMInstance::register_types(lua_State *L) { // TODO: add __type
luau_context ctx = L;
ctx.push_object();
ctx.rawset(LUA_GLOBALSINDEX,"vector"); // deyeet

ctx.newmetatable_type(ctx.UD_TRBXSCRIPTSIGNAL);
ctx.set_dtor(ctx.UD_TRBXSCRIPTSIGNAL, RBXScriptSignal::lua_destroy);
Expand All @@ -348,9 +346,20 @@ void RobloxVMInstance::register_types(lua_State *L) { // TODO: add __type
ctx.rawset(-2, "__newindex");
ctx.pop_stack(1);
}
void RobloxVMInstance::register_genv(lua_State *L) {
luau_context ctx = L;
ctx.push_object();
ctx.rawset(LUA_GLOBALSINDEX,"vector"); // deyeet

ctx.new_table();
ctx.push_object(&Instance::new_instance,"Instance::new");
ctx.rawset(-2,"new");
ctx.rawset(LUA_GLOBALSINDEX,"Instance");
}
RobloxVMInstance::RobloxVMInstance(lua_State *main) {
main_synchronized = new luau_State(this, main);
register_types(main);
register_genv(L);
}
RobloxVMInstance::~RobloxVMInstance() {
delete main_synchronized;
Expand Down
1 change: 1 addition & 0 deletions src/classes/rblx_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class RobloxVMInstance final {
return memrealloc(ptr, nsize);
}
void register_types(lua_State *L);
void register_genv(lua_State *L);
lua_State* create_lua_state() {
lua_State *L = lua_newstate(lua_alloc, nullptr);
::lua_pushlightuserdata(L, this);
Expand Down

0 comments on commit 3c45d1d

Please sign in to comment.