-->
Page 21 of 23

Re: [DEVELOPMENT] IOT example GPIO/ADC web client and web se

PostPosted: Wed Dec 03, 2014 4:47 am
by gerardwr
zeroday wrote:well I have been follow you posts everyday.
but I have no solutions in lua way, me a lua newbie too. :oops:
the first thing came into my head, is to make a api in C to do this,
take a lua statement, run it, and return a string result... but this is ugly...


Nice that you follow my struggle, thanks for your help.

Yep, an API in C, that's ugly ;) , and too complicated for me!

I'm glad that I'm not missing anything obvious here.

But wait……

I think I have found A solution in the elua -httpd webserver http://wiki.eluaproject.net/lhttpd)

There's a docode function in it, that works in nodeMco too. I takes a Lua statement as input in a string, executes the loadstring of the string, and returns the result in a string. It works by a temporary replacement of the print function by a function that prints to string. Neat huh!

I did a quick test:
Code: Select all> s=[[print(node.heap())]]
> a=docode(s)
> =a
16384
> s='for i=1,3 do print(i) end'
> out=docode(s)
> =out
1
2
3

> s='now introduce a lua error for i=1,3 do print(i) end'
> out=docode(s)
> =out
>>> Invalid Lua code <<<

>


My problem can be solved in this way, I guess.

Re: [DEVELOPMENT] IOT example GPIO/ADC web client and web se

PostPosted: Wed Dec 03, 2014 6:00 am
by frasenci
Thank you very much for fine example files.
I will test for my particular application and report back

Greetings
Francisco

Re: [DEVELOPMENT] IOT example GPIO/ADC web client and web se

PostPosted: Wed Dec 03, 2014 6:12 am
by zeroday
gerardwr wrote:
zeroday wrote:well I have been follow you posts everyday.
but I have no solutions in lua way, me a lua newbie too. :oops:
the first thing came into my head, is to make a api in C to do this,
take a lua statement, run it, and return a string result... but this is ugly...


Nice that you follow my struggle, thanks for your help.

Yep, an API in C, that's ugly ;) , and too complicated for me!

I'm glad that I'm not missing anything obvious here.

But wait……

I think I have found A solution in the elua -httpd webserver http://wiki.eluaproject.net/lhttpd)

There's a docode function in it, that works in nodeMco too. I takes a Lua statement as input in a string, executes the loadstring of the string, and returns the result in a string. It works by a temporary replacement of the print function by a function that prints to string. Neat huh!

I did a quick test:
Code: Select all> s=[[print(node.heap())]]
> a=docode(s)
> =a
16384
> s='for i=1,3 do print(i) end'
> out=docode(s)
> =out
1
2
3

> s='now introduce a lua error for i=1,3 do print(i) end'
> out=docode(s)
> =out
>>> Invalid Lua code <<<

>


My problem can be solved in this way, I guess.


Neat!! That's the true power of lua.

Re: [DEVELOPMENT] IOT example GPIO/ADC web client and web se

PostPosted: Wed Dec 03, 2014 6:34 am
by alonewolfx2
@gerardwr can you catch requested headers in your webserver?
Code: Select allAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive