{"action":"closed","issue":{"url":"https://api.github.com/repos/ThePhD/sol2/issues/416","repository_url":"https://api.github.com/repos/ThePhD/sol2","labels_url":"https://api.github.com/repos/ThePhD/sol2/issues/416/labels{/name}","comments_url":"https://api.github.com/repos/ThePhD/sol2/issues/416/comments","events_url":"https://api.github.com/repos/ThePhD/sol2/issues/416/events","html_url":"https://github.com/ThePhD/sol2/issues/416","id":232472890,"number":416,"title":"Question about usertype memory/Lua C API","user":{"login":"squeek502","id":2389051,"avatar_url":"https://avatars2.githubusercontent.com/u/2389051?v=3","gravatar_id":"","url":"https://api.github.com/users/squeek502","html_url":"https://github.com/squeek502","followers_url":"https://api.github.com/users/squeek502/followers","following_url":"https://api.github.com/users/squeek502/following{/other_user}","gists_url":"https://api.github.com/users/squeek502/gists{/gist_id}","starred_url":"https://api.github.com/users/squeek502/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squeek502/subscriptions","organizations_url":"https://api.github.com/users/squeek502/orgs","repos_url":"https://api.github.com/users/squeek502/repos","events_url":"https://api.github.com/users/squeek502/events{/privacy}","received_events_url":"https://api.github.com/users/squeek502/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-05-31T07:05:24Z","updated_at":"2017-05-31T10:26:37Z","closed_at":"2017-05-31T10:26:37Z","body":"I was trying to use the Lua C API to retrieve a pointer to a usertype that was bound by Sol2 and got a bit confused. After some testing, it seems like what works (in the few cases I tried) is `T* val = *static_cast<T**>(lua_touserdata(L, -1))`, and I'm confused as to whether or not that conflicts with [the usertype memory docs](http://sol2.readthedocs.io/en/latest/api/usertype_memory.html).\r\n\r\nI guess I don't have a specific question, just want to make sure this is intended.\r\n\r\nHere's some test code that tests against the current functionality:\r\n```c++\r\n#define SOL_CHECK_ARGUMENTS\r\n#include <catch.hpp>\r\n#include <sol.hpp>\r\n\r\nTEST_CASE(\"getting a usertype using the Lua C API\")\r\n{\r\n\tstruct thing {\r\n\t\tint val;\r\n\t};\r\n\r\n\tsol::state lua;\r\n\tlua.open_libraries(sol::lib::base);\r\n\r\n\tlua.new_usertype<thing>(\"thing\");\r\n\r\n\tthing a;\r\n\ta.val = 10;\r\n\r\n\tSECTION(\"pushing the value\")\r\n\t{\r\n\t\tlua[\"a\"] = a;\r\n\t\tlua_getglobal(lua, \"a\");\r\n\t\tREQUIRE(lua_isuserdata(lua, -1));\r\n\t\tvoid* raw = lua_touserdata(lua, -1);\r\n\t\tthing* actual = *static_cast<thing**>(raw);\r\n\t\tREQUIRE(actual->val == 10);\r\n\t\tlua_pop(lua, 1);\r\n\t}\r\n\r\n\tSECTION(\"pushing the pointer\")\r\n\t{\r\n\t\tlua[\"a\"] = &a;\r\n\t\tlua_getglobal(lua, \"a\");\r\n\t\tREQUIRE(lua_isuserdata(lua, -1));\r\n\t\tvoid* raw = lua_touserdata(lua, -1);\r\n\t\tthing* actual = *static_cast<thing**>(raw);\r\n\t\tREQUIRE(actual->val == 10);\r\n\t\tlua_pop(lua, 1);\r\n\t}\r\n}\r\n```"}}
{"actor":{"display_login":"ThePhD"}}