Is there a way to access the content width/height as defined in config.lua from the native side when doing a plugin?
Not sure if this is what you want, but you can. Like, you can call any Lua function from native code, as well as ‘require “config”’ and get whatever you want from it.
But generally there are convenience functions available for work with Native, like translating coordinates from Lua to native. For example on Objective C side its - (CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint in CoronaRuntime.h.
If you want to read config Lua for some reason, you can totally do it. Here is some code, I think it can be done like this. Also, note, I did not test this code. This is just a sample:
int w=-1,h=-1; lua\_getglobal(L, "application"); //back up existing global 'application' variable if any lua\_getglobal(L, "require" ); lua\_pushliteral(L, "config" ); lua\_pcall(L, 1, 0); lua\_getglobal(L, "application" ); // application. if(lua\_istable(L,-1)) { lua\_getfield(L, -1, "content"); // application.content. if(lua\_istable(L,-1)) { lua\_getfield(L, -1, "width"); // application.content.width if(lua\_isnumber(L, -1)) { w = lua\_tonumber(L, -1); } lua\_pop(L, 1); lua\_getfield(L, -1, "height"); // application.content.height if(lua\_isnumber(L, -1)) { h = lua\_tonumber(L, -1); } lua\_pop(L, 1); } lua\_pop(L, 1); } lua\_pop(L, 1); // pop config's application lua\_setglobal(L, "application"); // restore 'application' and pop it
Thanks Vlads
(CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint
Was exactly the what I was trying to achieve.
The code example was educational too :)
Not sure if this is what you want, but you can. Like, you can call any Lua function from native code, as well as ‘require “config”’ and get whatever you want from it.
But generally there are convenience functions available for work with Native, like translating coordinates from Lua to native. For example on Objective C side its - (CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint in CoronaRuntime.h.
If you want to read config Lua for some reason, you can totally do it. Here is some code, I think it can be done like this. Also, note, I did not test this code. This is just a sample:
int w=-1,h=-1; lua\_getglobal(L, "application"); //back up existing global 'application' variable if any lua\_getglobal(L, "require" ); lua\_pushliteral(L, "config" ); lua\_pcall(L, 1, 0); lua\_getglobal(L, "application" ); // application. if(lua\_istable(L,-1)) { lua\_getfield(L, -1, "content"); // application.content. if(lua\_istable(L,-1)) { lua\_getfield(L, -1, "width"); // application.content.width if(lua\_isnumber(L, -1)) { w = lua\_tonumber(L, -1); } lua\_pop(L, 1); lua\_getfield(L, -1, "height"); // application.content.height if(lua\_isnumber(L, -1)) { h = lua\_tonumber(L, -1); } lua\_pop(L, 1); } lua\_pop(L, 1); } lua\_pop(L, 1); // pop config's application lua\_setglobal(L, "application"); // restore 'application' and pop it
Thanks Vlads
(CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint
Was exactly the what I was trying to achieve.
The code example was educational too :)