snaptoken / lua-tutorial

Lua From Scratch (WIP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lua code examples

osiyuk opened this issue · comments

I think the first thing to do is to get codebase of simple Lua scripts/programs... or prepare it yourself. It will be helpful as starting point to think about parser/tokenizer and for testing purposes.

The idea is simple: if you want to test compiler, you'll need to prepare several code examples.

osiyuk@4253409

@yjerem What you think?

Currently I'm thinking the beginning of the book will just add Lua features to C, so you can write programs in C in sort of a Lua style using the Lua API. Since Lua is made to be embeddable in C and all. But I'm not sure about this, I'm still in the very early stages of planning this out.

But yeah, eventually we want the reader to build something that can actually parse and run some real Lua code. I'm thinking we'll start with parsing expressions, and implement sort of a "data-language" kinda like JSON, where it just parses literal Lua values (including arrays/tables) and gives you back an object and an API to traverse that object.

Then it'll proceed to add actual language features to the "data-language", like variables, functions, flow control, and so on. At that point it might be useful to have example Lua programs, although we might be able to let the reader make up their own programs to test with.

But you bring up a real good point about needing to test the program on something. I think it's important for the reader to be able to compile their program every few steps and test it out on something to actually see the results of the code they typed in. It's much more satisfying to build something big when you can constantly run it and see the changes yourself.