lua-users home
lua-l archive

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


I'm using LuaGL in the code below and want to monitor calls to the gl
table because I need to check if there is a valid OpenGL context
before letting the function call proceed.  Surprisingly (to me at
least), the code below doesn't work properly.  Calls like gl.Color(1.,
1., 0., 1.) work as expected, but calls like gl.Begin("LINES") produce
a "indexing a function value" error.  Given the code below, why would
this happen?  It doesn't make any sense to me at all.

Also note that this.context is a globally accessible variable.  If you
have LuaGL and want to test this code, just take that part out.


___gl = gl
gl_temp_meta = {}
gl_temp_meta.__index = 	function(t, k)
							if(this.context ~= 0) then
								return function(...)
											local args = {...}
											print("\nargs")
											for k, v in pairs(args) do
												print(v)
											end

											return ___gl[k](...)
										end
								else
									return 	function()
												print("No valid OpenGL context")
											end
								end
						end

gl_temp = {}
setmetatable(gl_temp, gl_temp_meta)

gl = gl_temp

function draw()
	local C = gl.Color
	local B = gl.Begin
	print("C: " .. tostring(C))
	print("B: " .. tostring(B))
	

	gl.Color(1., 1., 0., 1.)
	gl.Begin("LINES")
		gl.Vertex(-1., 0., 0.)
		gl.Vertex(1., 0., 0.)
	gl.End()
end






thanks,
wes