Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to luaL_getmetatable #6

Open
PolEpie opened this issue Mar 7, 2023 · 5 comments
Open

Access to luaL_getmetatable #6

PolEpie opened this issue Mar 7, 2023 · 5 comments

Comments

@PolEpie
Copy link

PolEpie commented Mar 7, 2023

Hi, i would like access to luaL_getmetatable to retrieve my metatable id but it get me this
thread '<unnamed>' panicked at 'Failed to find symbol "luaL_getmetatable "

I've seen that luaL_newmetatable is already implemented so it should be easy to do

@WilliamVenner
Copy link
Owner

Hey, luaL_getmetatable isn't actually a function, it's a macro, as defined here: https://github.com/LuaJIT/LuaJIT/blob/505e2c03de35e2718eef0d2d3660712e06dadf1f/src/lauxlib.h#L118

You'll just have to use lua.get_field(LUA_REGISTRYINDEX, foo) where foo is the metatable id :)

@PolEpie
Copy link
Author

PolEpie commented Mar 8, 2023

But how can i get the metatable id since lua.new_metatable(lua_string!("MongoDBCollection")); return just a bool

@WilliamVenner
Copy link
Owner

lua_string!("MongoDBCollection") should work as metatable id

@PolEpie
Copy link
Author

PolEpie commented Mar 8, 2023

Ahah thx you saved me, and last question how can i push lua.new_userdata ? cause i'm just calling it and it give me attempt to index a nil value

@PolEpie
Copy link
Author

PolEpie commented Mar 9, 2023

My issue is more when define metatable, i've use that but doesnt seem to work, could you help me a little bit cause with that when i'm running getmetatable("MongoDBCollection) it return just __index

if lua.is_nil(-1) {
    lua.pop();
    lua.new_table();
}

lua.new_metatable(lua_string!("MongoDBCollection"));

lua.push_value(-1);

//lua.get_field(-1, lua_string!("MongoDBCollection"));
lua.set_field(-2, lua_string!("__index"));

lua.push_function(mongodb_database);
lua.set_field(-2, lua_string!("database"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants