Tag:Lua programming
-
Some basic syntax sorting in Lua programming
Lua is quite easy to learn. Let’s start creating the first Lua program! First Lua programInteractive mode programming: Lua provides a pattern called interactive mode. In this mode, you can type one instruction after another and get immediate results. The shell used in this is lua-i or just Lua’s commands are called. Once in this […]
-
Tutorial on using nested loops in Lua programming
Luaprograming languageAllows you to use one loop to embed another. Several examples are presented below to illustrate this concept. grammar Nested loop syntax statements in Lua are as follows: Copy codeThe code is as follows: for init,max/min value, increment do for init,max/min value, increment do statement(s) end statement(s) end […]
-
Analysis of exception handling in Lua programming
Error handling is required Error handling is necessary because real-world operations usually require complex operations, including file operations, database transactions and web service calls. No one cares about the wrong business, causing great losses when it involves confidential information or money transactions. In any programming, there are always requirements for error handling. There are two […]
-
Lua programming example (I): select, debug, variable parameters, table operation, error
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 […]
-
Lua programming example (3): sparse table, double ended queue, formatted output, formatted output of table and circular table
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 […]
-
Lua programming example (4): table library, string library and system library of lua standard library
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 […]
-
Lua programming example (V): reading and adding Lua table in C language
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 […]
-
Lua programming example (6): calling Lua function in C language
C + + end: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include “stdafx.h” lua_State *L; void load_lua(lua_State **L,char *filename){ *L=luaL_newstate(); luaL_openlibs(*L); if(luaL_loadfile(*L,filename) || lua_pcall(*L,0,0,0)){ luaL_error(*L,”load file error! %s”,lua_tostring(*L,-1)); } […]
-
Lua programming example (VII): basic logic of collaborative program
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 co=coroutine.create(function() print(“hi”) end) print(coroutine.status(co)) coroutine.resume(co) print(coroutine.status(co)) print() co=coroutine.create(function() for i=1,2 […]
-
Lua programming example (8): producer consumer problem
This problem is quite classic. Multithreading in almost all languages will be involved, but I didn’t expect Lua to be so complex and crazy It took me a long time to understand. Let’s start with the logic diagram: Call the consumer at the beginning. When the consumer needs the value, call the producer production […]