Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/script_engine/OLD/This.cc @ 8219

Last change on this file since 8219 was 8061, checked in by bensch, 19 years ago

merged the scriptengine back to the trunk

File size: 1.3 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[7654]12   main-programmer: Silvan Nellen
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[7654]18#include "This.h"
19#include "luaincl.h"
[1853]20
[7654]21namespace OrxScript
[3365]22{
[7654]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);
[4320]31
[7654]32      // replace it with our new one
33      lua_rawgeti(state, LUA_REGISTRYINDEX, iRef);
34      lua_setglobal (state, "this");
35    }
36  }
[4320]37
[7654]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  }
[3365]49}
Note: See TracBrowser for help on using the repository browser.