Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/lib/script_engine/This.cc @ 7654

Last change on this file since 7654 was 7654, checked in by bensch, 18 years ago

orxonox/script_engine: moved everything into cc-files

File size: 1.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Silvan Nellen
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "This.h"
19#include "luaincl.h"
20
21namespace OrxScript
22{
23  LuaThis::LuaThis (LuaVirtualMachine& vm, int iRef) : oldReference (0), virtualMachine (vm)
24  {
25    lua_State *state = (lua_State *) vm;
26    if (vm.isOk ())
27    {
28      // Save the old "this" table
29      lua_getglobal (state, "this");
30      oldReference = luaL_ref (state, LUA_REGISTRYINDEX);
31
32      // replace it with our new one
33      lua_rawgeti(state, LUA_REGISTRYINDEX, iRef);
34      lua_setglobal (state, "this");
35    }
36  }
37
38  LuaThis::~LuaThis (void)
39  {
40    lua_State *state = (lua_State *) virtualMachine;
41    if (oldReference > 0 && virtualMachine.isOk ())
42    {
43      // Replace the old "this" table
44      lua_rawgeti(state, LUA_REGISTRYINDEX, oldReference);
45      lua_setglobal (state, "this");
46      luaL_unref (state, LUA_REGISTRYINDEX, oldReference);
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.