# Content width/height

**URL:** <https://forums.solar2d.com/t/content-width-height/350388>\
**Category:** Native builds\
**Created:** [September 3, 2019, 10:39pm UTC](https://forums.solar2d.com/t/content-width-height/350388 "2019-09-03T22:39:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ojnab](https://forums.solar2d.com/user_avatar/forums.solar2d.com/ojnab/32/94_2.png) [@ojnab](https://forums.solar2d.com/u/ojnab)\
**Post date:** [September 3, 2019, 10:39pm UTC](https://forums.solar2d.com/t/content-width-height/350388/1 "2019-09-03T22:39:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [September 4, 2019, 9:43am UTC](https://forums.solar2d.com/t/content-width-height/350388/2 "2019-09-04T09:43:16Z")

</div>

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&nbsp;- (CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint in CoronaRuntime.h.  
&nbsp;  
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:

&nbsp;

```
&nbsp; &nbsp; int w=-1,h=-1; &nbsp; &nbsp; lua\_getglobal(L, "application"); //back up existing global 'application' variable if any&nbsp; &nbsp; &nbsp; lua\_getglobal(L, "require" ); &nbsp; &nbsp; lua\_pushliteral(L, "config" ); &nbsp; &nbsp; lua\_pcall(L, 1, 0); &nbsp; &nbsp; lua\_getglobal(L, "application" ); // application. &nbsp; &nbsp; if(lua\_istable(L,-1)) { &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "content"); // application.content. &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_istable(L,-1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "width"); // application.content.width &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_isnumber(L, -1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = lua\_tonumber(L, -1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "height"); // application.content.height &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_isnumber(L, -1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h = lua\_tonumber(L, -1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; } &nbsp; &nbsp; lua\_pop(L, 1); // pop config's application &nbsp; &nbsp; lua\_setglobal(L, "application"); // restore 'application' and pop it
```

---

<div class="post-metadata">

**Author:** ![ojnab](https://forums.solar2d.com/user_avatar/forums.solar2d.com/ojnab/32/94_2.png) [@ojnab](https://forums.solar2d.com/u/ojnab)\
**Post date:** [September 6, 2019, 10:34am UTC](https://forums.solar2d.com/t/content-width-height/350388/3 "2019-09-06T10:34:32Z")

</div>

Thanks Vlads

(CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint

Was exactly the what I was trying to achieve.

The code example was educational too&nbsp; :)&nbsp;

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [September 4, 2019, 9:43am UTC](https://forums.solar2d.com/t/content-width-height/350388/4 "2019-09-04T09:43:16Z")

</div>

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&nbsp;- (CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint in CoronaRuntime.h.  
&nbsp;  
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:

&nbsp;

```
&nbsp; &nbsp; int w=-1,h=-1; &nbsp; &nbsp; lua\_getglobal(L, "application"); //back up existing global 'application' variable if any&nbsp; &nbsp; &nbsp; lua\_getglobal(L, "require" ); &nbsp; &nbsp; lua\_pushliteral(L, "config" ); &nbsp; &nbsp; lua\_pcall(L, 1, 0); &nbsp; &nbsp; lua\_getglobal(L, "application" ); // application. &nbsp; &nbsp; if(lua\_istable(L,-1)) { &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "content"); // application.content. &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_istable(L,-1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "width"); // application.content.width &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_isnumber(L, -1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = lua\_tonumber(L, -1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_getfield(L, -1, "height"); // application.content.height &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(lua\_isnumber(L, -1)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h = lua\_tonumber(L, -1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; lua\_pop(L, 1); &nbsp; &nbsp; } &nbsp; &nbsp; lua\_pop(L, 1); // pop config's application &nbsp; &nbsp; lua\_setglobal(L, "application"); // restore 'application' and pop it
```

---

<div class="post-metadata">

**Author:** ![ojnab](https://forums.solar2d.com/user_avatar/forums.solar2d.com/ojnab/32/94_2.png) [@ojnab](https://forums.solar2d.com/u/ojnab)\
**Post date:** [September 6, 2019, 10:34am UTC](https://forums.solar2d.com/t/content-width-height/350388/5 "2019-09-06T10:34:32Z")

</div>

Thanks Vlads

(CGPoint)coronaPointToUIKitPoint:(CGPoint)coronaPoint

Was exactly the what I was trying to achieve.

The code example was educational too&nbsp; :)&nbsp;
