Thursday, October 1, 2020

NodeMCU - Enabling Lua 5.3

I could write this as a 1 line post, but I'm going to pad it out a little.

So, if you've ever used Lua on a NodeMCU device, like an ESP-8266, you know that it defaults to Lua 5.1. Not that there is anything wrong with that, but if you read the whitepaper, you'll see that 5.3 has some neat features. But the question I couldn't find the answer to is: How do you cause the project to compile with Lua 5.3.

I'm as good as the next guy when it comes to web searches, maybe better than average. My success rate is pretty high, but I couldn't find the right search terms for that one. AFAIK - this will be the first blog post I've found about it; Which is the reason I'm writing it.

I build my nodeMCU firmware natively, on a Linux box running FC-32, but I'm pretty sure it doesn't matter how you build yours.

The quick answer:

$ export LUA=53 && make

I couldn't get it to build in the master branch or the dev branch, but I checked out the release branch and it built just fine there. I flashed it to my D1 Mini Pro and voilĂ .

> print(_VERSION)

Lua 5.3

Just like that. I'd rather not explain how I figured it out, makes it seem like I'm smarter than I am. But it involved some poking around the source code until eventually I found, in /app/Makefile. Some lucky 'grep'ing.

# Handle Lua Directory selector
ifeq ("$(LUA)","53")
  LUA_DIR := lua53
else
  LUA_DIR := lua
endif
I hope that helps.

PD

Note: You may need to make clean if you've been building against Lua 5.1

Note2: To my surprise, it was still necessary to use '=' before displaying the results of function calls when using the command line. E.g.: wifi.sta.getip() exits silently, whereas =wifi.sta.getip() will display the results of that call. That changed after 5.2 but I guess it didn't make it to the nodeMCU version. Odd.

No comments:

Post a Comment