{"action":"created","issue":{"url":"https://api.github.com/repos/ThePhD/sol2/issues/595","repository_url":"https://api.github.com/repos/ThePhD/sol2","labels_url":"https://api.github.com/repos/ThePhD/sol2/issues/595/labels{/name}","comments_url":"https://api.github.com/repos/ThePhD/sol2/issues/595/comments","events_url":"https://api.github.com/repos/ThePhD/sol2/issues/595/events","html_url":"https://github.com/ThePhD/sol2/issues/595","id":299183287,"number":595,"title":"Wrap Eigen Matrix Fails","user":{"login":"rhythmchicago","id":15332316,"avatar_url":"https://avatars2.githubusercontent.com/u/15332316?v=4","gravatar_id":"","url":"https://api.github.com/users/rhythmchicago","html_url":"https://github.com/rhythmchicago","followers_url":"https://api.github.com/users/rhythmchicago/followers","following_url":"https://api.github.com/users/rhythmchicago/following{/other_user}","gists_url":"https://api.github.com/users/rhythmchicago/gists{/gist_id}","starred_url":"https://api.github.com/users/rhythmchicago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhythmchicago/subscriptions","organizations_url":"https://api.github.com/users/rhythmchicago/orgs","repos_url":"https://api.github.com/users/rhythmchicago/repos","events_url":"https://api.github.com/users/rhythmchicago/events{/privacy}","received_events_url":"https://api.github.com/users/rhythmchicago/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-22T00:45:55Z","updated_at":"2018-02-22T01:06:12Z","closed_at":null,"author_association":"NONE","body":"Hello, everyone.\r\n\r\nVery much enjoying sol2. I'm trying to wrap and expose an Eigen::MatrixXf to a lua script. It took me awhile to figure out a way that would compile, but I'm not sure if I'm doing this the best way. I was hoping I could get feedback.\r\n\r\n```\r\nclass MatrixXf : Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> \r\n{\r\npublic:\r\n\tMatrixXf(int row, int col) :\r\n\t\tEigen::MatrixXf(row, col)\r\n\t{\r\n\t}\r\n\r\n\tvoid resize(int row, int col)\r\n\t{\r\n\t\tEigen::MatrixXf::resize(row, col);\r\n\t}\r\n};\r\n\r\n...\r\n\r\nvoid LuaLab::registerLuaExtensions(sol::state& lua)\r\n{\r\n        ....\r\n\tlua.new_usertype<MatrixXf>(\r\n\t\t\"matrix\",\r\n\t\tsol::constructors<MatrixXf(int,int)>(),\r\n\t\t\"resize\", &MatrixXf::resize\r\n\t);\r\n}\r\n\r\n```\r\n\r\nFrom a lua script:\r\n\r\n```\r\nm = matrix.new(5,5)\r\nm:resize(2,2)\r\n```\r\n\r\nIt works, but I'm wondering if I'm making things overly-complicated. Unfortunately, I've not found a way to 'typedef' or more directly wrap the Eigen template. For example, both of these fail to compile:\r\n\r\n1. Replace the class with a typedef.\r\ntypedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> MatrixXf;\r\n2. Publicly sub-class the Eigen::Matrix\r\nclass MatrixXf : **public** Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> \r\n\r\nThe error is the same for both modifications:\r\nerror C2440: 'initializing': cannot convert from 'initializer list' to 'luaL_Reg'\r\n\r\n\r\nIs there a better way to register the usertype where I wouldn't have to replicate the entire API of the template?\r\n\r\n\r\nThanks!\r\n\r\nLanguage: C++\r\nMSVC 2017"},"comment":{"url":"https://api.github.com/repos/ThePhD/sol2/issues/comments/367532713","html_url":"https://github.com/ThePhD/sol2/issues/595#issuecomment-367532713","issue_url":"https://api.github.com/repos/ThePhD/sol2/issues/595","id":367532713,"user":{"login":"rhythmchicago","id":15332316,"avatar_url":"https://avatars2.githubusercontent.com/u/15332316?v=4","gravatar_id":"","url":"https://api.github.com/users/rhythmchicago","html_url":"https://github.com/rhythmchicago","followers_url":"https://api.github.com/users/rhythmchicago/followers","following_url":"https://api.github.com/users/rhythmchicago/following{/other_user}","gists_url":"https://api.github.com/users/rhythmchicago/gists{/gist_id}","starred_url":"https://api.github.com/users/rhythmchicago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhythmchicago/subscriptions","organizations_url":"https://api.github.com/users/rhythmchicago/orgs","repos_url":"https://api.github.com/users/rhythmchicago/repos","events_url":"https://api.github.com/users/rhythmchicago/events{/privacy}","received_events_url":"https://api.github.com/users/rhythmchicago/received_events","type":"User","site_admin":false},"created_at":"2018-02-22T01:06:12Z","updated_at":"2018-02-22T01:06:12Z","author_association":"NONE","body":"\tlua.new_usertype<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>> (\r\n\t\t\"eigen\",\r\n\t\tsol::constructors<sol::types<Eigen::DenseIndex, Eigen::DenseIndex>>()\r\n\t);\r\n\r\nSame error, but now it looks like it's the optional arguments in the constructor:\r\n\r\n1>        with\r\n1>        [\r\n1>            Class=Eigen::Matrix<float,-1,-1,0,-1,-1>\r\n1>        ]\r\n\r\nIs there a way to account for that?\r\n"}}
{"actor":{"display_login":"rhythmchicago"}}