Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

REST API communication through LUA code
Started by srotti May 29 2019 05:48 AM

- - - - -
3 replies to this topic
rest restapi lua network network.request
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

srotti

[GLOBAL: userInfoPane.html]
srotti
  • Observer

  • 2 posts
  • Corona SDK

I'm a beginner in Lua just started it. I was trying to call a restapi using lua but ,I'm facing issues 

 

local headers = {}
headers["Content-Type"] = "application/json"
headers["X-API-Key"] = "u0X9q5qPvJ42ljksahdshdjsacmMlrU8jaP2g1O"
local body = "testfromLua"
local params = {}
params.headers = headers
params.body = body
network.request("https://"Sample API Url", "POST", networkListener, params)

 

The error is

attempt to index local 'network' (a nil value)

so what could be the problem? 

 

 

Thank you.



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,042 posts
  • Enterprise

Hi @srotti and welcome to the Corona Labs community forums?

 

Are you using straight up Lua or are you using Corona?

 

network.* are Corona API"s and are not something that's included with Lua.

 

Rob



[TOPIC: post.html]
#3

srotti

[GLOBAL: userInfoPane.html]
srotti
  • Observer

  • 2 posts
  • Corona SDK

Thanks @Rob but how do I use Corona API's inside Lua, can I get some procedure about it. It would be helpful.

[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,042 posts
  • Enterprise

You can't. Corona uses Lua, Lua doesn't use Corona. Corona isn't a library of Lua APIs. Corona is an Engine/Framework to build apps in that happens to use Lua as its scripting language. You would have to use Corona to build your applications.

 

Rob




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: rest, restapi, lua, network, network.request