Skip to content
This repository was archived by the owner on Dec 29, 2024. It is now read-only.

Commit 6d6248a

Browse files
authored
Remove expose_constructor (#148)
1 parent 63e8aa0 commit 6d6248a

File tree

6 files changed

+2
-44
lines changed

6 files changed

+2
-44
lines changed

doc_classes/LuaAPI.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@
4141
Loads a string with luaL_loadstring() and executes the top of the stack. Returns any errors.
4242
</description>
4343
</method>
44-
<method name="expose_constructor">
45-
<return type="LuaError" />
46-
<param index="0" name="LuaConstructorName" type="String" />
47-
<param index="1" name="Object" type="Object" />
48-
<description>
49-
Accepts any object that has a new() method. Allows lua to call the constructor aka the new() method. Exposed as a global with the given name.
50-
</description>
51-
</method>
5244
<method name="function_exists">
5345
<return type="bool" />
5446
<param index="0" name="LuaFunctionName" type="String" />

project/testing/tests/LuaAPI.expose_constructor.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ func _ready():
1313

1414
lua = LuaAPI.new()
1515
lua.permissive = true
16-
var err = lua.expose_constructor("TestObj", TestObject)
16+
var err = lua.push_variant("TestObj", TestObject.new)
1717
if err is LuaError:
1818
errors.append(err)
1919
fail()
2020

2121
# testName and testDescription are for any needed context about the test.
2222
testName = "LuaAPI.expose_constructor"
2323
testDescription = "
24-
Test LuaAPI.expose_constructor.
24+
Test LuaAPI.push_variant with a object constructor.
2525
Exoposes a object constructor for TestObject which contains one variable. A string
2626
lua calls the constructor and then sets the string to 'Hello from lua!'.
2727
We also test pulling it back to GD and confirm the contents of the string.

src/classes/luaAPI.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ void LuaAPI::_bind_methods() {
3030
ClassDB::bind_method(D_METHOD("get_memory_usage"), &LuaAPI::getMemoryUsage);
3131
ClassDB::bind_method(D_METHOD("push_variant", "Name", "var"), &LuaAPI::pushGlobalVariant);
3232
ClassDB::bind_method(D_METHOD("pull_variant", "Name"), &LuaAPI::pullVariant);
33-
ClassDB::bind_method(D_METHOD("expose_constructor", "LuaConstructorName", "Object"), &LuaAPI::exposeObjectConstructor);
3433
ClassDB::bind_method(D_METHOD("call_function", "LuaFunctionName", "Args"), &LuaAPI::callFunction);
3534
ClassDB::bind_method(D_METHOD("call_function_ref", "Args", "LuaFunctionRef"), &LuaAPI::callFunctionRef);
3635
ClassDB::bind_method(D_METHOD("function_exists", "LuaFunctionName"), &LuaAPI::luaFunctionExists);
@@ -140,11 +139,6 @@ LuaError *LuaAPI::pushGlobalVariant(String name, Variant var) {
140139
return state.pushGlobalVariant(name, var);
141140
}
142141

143-
// Calls LuaState::exposeObjectConstructor()
144-
LuaError *LuaAPI::exposeObjectConstructor(String name, Object *obj) {
145-
return state.exposeObjectConstructor(name, obj);
146-
}
147-
148142
// addFile() calls luaL_loadfille with the absolute file path
149143
LuaError *LuaAPI::doFile(String fileName) {
150144
// push the error handler onto the stack

src/classes/luaAPI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class LuaAPI : public RefCounted {
5050
LuaError *doFile(String fileName);
5151
LuaError *doString(String code);
5252
LuaError *pushGlobalVariant(String name, Variant var);
53-
LuaError *exposeObjectConstructor(String name, Object *obj);
5453

5554
Ref<LuaCoroutine> newCoroutine();
5655
Ref<LuaCoroutine> getRunningCoroutine();

src/luaState.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class LuaState {
3131

3232
LuaError *pushVariant(Variant var) const;
3333
LuaError *pushGlobalVariant(String name, Variant var);
34-
LuaError *exposeObjectConstructor(String name, Object *obj);
3534
LuaError *handleError(int lua_error) const;
3635

3736
static LuaAPI *getAPI(lua_State *state);

src/metatables.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,6 @@
2222
lua_pushcfunction(lua_state, LUA_LAMBDA_TEMPLATE(_f_)); \
2323
lua_settable(lua_state, metatable_index - 2);
2424

25-
// Expose the constructor for a object to lua
26-
LuaError *LuaState::exposeObjectConstructor(String name, Object *obj) {
27-
// Make sure we are able to call new
28-
if (!obj->has_method("new")) {
29-
return LuaError::newError("during \"LuaState::exposeObjectConstructor\" method 'new' does not exist.", LuaError::ERR_RUNTIME);
30-
}
31-
lua_pushlightuserdata(L, obj);
32-
33-
lua_pushcclosure(L, LUA_LAMBDA_TEMPLATE({
34-
Object *inner_obj = (Object *)lua_touserdata(inner_state, lua_upvalueindex(1));
35-
36-
Variant *userdata = (Variant *)lua_newuserdata(inner_state, sizeof(Variant));
37-
Variant ret = inner_obj->call("new");
38-
39-
memnew_placement(userdata, Variant(ret));
40-
41-
luaL_setmetatable(inner_state, "mt_Object");
42-
43-
return 1;
44-
}),
45-
1);
46-
47-
lua_setglobal(L, name.ascii().get_data());
48-
return nullptr;
49-
}
50-
5125
// Expose the default constructors
5226
void LuaState::exposeConstructors() {
5327
lua_pushcfunction(L, LUA_LAMBDA_TEMPLATE({

0 commit comments

Comments
 (0)