lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> local b = (loadstring or load)("function a()\n  print(1)\n  print(2)\nend")

The value of b is the "main" function of the chunk
       
     1	function a()
     2	  print(1)
     3	  print(2)
     4	end

This main function only has *two* executable instructions:
	- an assigment to a global variable 'a' on line 1
	- an implicit return after line 4

In other words, the main function is essentially this:
	a = function ()
	 ...
	end return

Hence the list of active lines you see.

See also the output of chunk given by luac -l:

main <2:0,0> (3 instructions at 0x7f9228c016d0)
0+ params, 2 slots, 1 upvalue, 0 locals, 1 constant, 1 function
	1	[4]	CLOSURE  	0 0	; 0x7f9228c01910
	2	[1]	SETTABUP 	0 -1 0	; _ENV "a"
	3	[4]	RETURN   	0 1

function <2:1,4> (7 instructions at 0x7f9228c01910)
0 params, 2 slots, 1 upvalue, 0 locals, 3 constants, 0 functions
	1	[2]	GETTABUP 	0 0 -1	; _ENV "print"
	2	[2]	LOADK    	1 -2	; 1
	3	[2]	CALL     	0 2 1
	4	[3]	GETTABUP 	0 0 -1	; _ENV "print"
	5	[3]	LOADK    	1 -3	; 2
	6	[3]	CALL     	0 2 1
	7	[4]	RETURN   	0 1