Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Content width/height
Started by ojnab Sep 03 2019 02:39 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ojnab

[GLOBAL: userInfoPane.html]
ojnab
  • Contributor

  • 574 posts
  • Corona SDK

Is there a way to access the content width/height as defined in config.lua from the native side when doing a plugin?

 

 



[TOPIC: post.html]
#2

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 852 posts
  • Corona Staff

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


[TOPIC: post.html]
#3

ojnab

[GLOBAL: userInfoPane.html]
ojnab
  • Contributor

  • 574 posts
  • Corona SDK

Thanks Vlads

 

(CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint

Was exactly the what I was trying to achieve.

 

The code example was educational too  :) 




[topic_controls]
[/topic_controls]