initial
This commit is contained in:
284
vscript/languages/lua/vlua/vec3.cpp
Normal file
284
vscript/languages/lua/vlua/vec3.cpp
Normal file
@@ -0,0 +1,284 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(OSX) && !defined (LINUX)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#if !defined(OSX) && !defined (LINUX)
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "vec3.h"
|
||||
|
||||
|
||||
#define VEC3_TYPE "Vec3"
|
||||
#define VEC3_NAME "Vec3"
|
||||
|
||||
|
||||
Vector *lua_getvec3( lua_State *pState, int i )
|
||||
{
|
||||
if ( luaL_checkudata( pState, i, VEC3_TYPE ) == NULL )
|
||||
{
|
||||
luaL_typerror( pState, i, VEC3_TYPE );
|
||||
}
|
||||
|
||||
return ( Vector * )lua_touserdata( pState, i );
|
||||
}
|
||||
|
||||
|
||||
Vector lua_getvec3ByValue( lua_State *pState, int i )
|
||||
{
|
||||
if ( lua_isnumber( pState, i ) )
|
||||
{
|
||||
float flValue = lua_tonumber( pState, i );
|
||||
|
||||
return Vector( flValue, flValue, flValue );
|
||||
}
|
||||
if ( luaL_checkudata( pState, i, VEC3_TYPE ) == NULL )
|
||||
{
|
||||
luaL_typerror( pState, i, VEC3_TYPE );
|
||||
}
|
||||
|
||||
return *( Vector * )lua_touserdata( pState, i );
|
||||
}
|
||||
|
||||
|
||||
static Vector *lua_allocvec3( lua_State *pState )
|
||||
{
|
||||
Vector *v =( Vector *)lua_newuserdata( pState, sizeof( Vector ) );
|
||||
luaL_getmetatable( pState, VEC3_TYPE );
|
||||
lua_setmetatable( pState, -2 );
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
Vector *lua_newvec3( lua_State *pState, const Vector *Value )
|
||||
{
|
||||
Vector *v;
|
||||
|
||||
v = lua_allocvec3( pState );
|
||||
v->x = Value->x;
|
||||
v->y = Value->y;
|
||||
v->z = Value->z;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_new( lua_State *pState )
|
||||
{
|
||||
Vector *v;
|
||||
|
||||
lua_settop( pState, 3 );
|
||||
v = lua_allocvec3( pState );
|
||||
v->x = luaL_optnumber( pState, 1, 0 );
|
||||
v->y = luaL_optnumber( pState, 2, 0 );
|
||||
v->z = luaL_optnumber( pState, 3, 0 );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_index( lua_State *pState )
|
||||
{
|
||||
const char *pszKey = luaL_checkstring( pState, 2 );
|
||||
|
||||
if ( pszKey[ 1 ] == '\0' )
|
||||
{
|
||||
Vector *v = lua_getvec3( pState, 1 );
|
||||
switch ( pszKey[ 0 ] )
|
||||
{
|
||||
case '1': case 'x': case 'r':
|
||||
lua_pushnumber( pState, v->x );
|
||||
return 1;
|
||||
|
||||
case '2': case 'y': case 'g':
|
||||
lua_pushnumber( pState, v->y );
|
||||
return 1;
|
||||
|
||||
case '3': case 'z': case 'b':
|
||||
lua_pushnumber( pState, v->z );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
lua_getfield( pState, LUA_REGISTRYINDEX, VEC3_TYPE );
|
||||
lua_pushstring( pState, pszKey );
|
||||
lua_rawget( pState, -2 );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_newindex( lua_State *pState )
|
||||
{
|
||||
const char *pszKey = luaL_checkstring( pState, 2 );
|
||||
|
||||
if ( pszKey[ 1 ] == '\0' )
|
||||
{
|
||||
Vector *v = lua_getvec3( pState, 1 );
|
||||
float flValue = luaL_checknumber( pState, 3 );
|
||||
switch ( pszKey[ 0 ] )
|
||||
{
|
||||
case '1': case 'x': case 'r':
|
||||
v->x = flValue;
|
||||
break;
|
||||
|
||||
case '2': case 'y': case 'g':
|
||||
v->y = flValue;
|
||||
break;
|
||||
|
||||
case '3': case 'z': case 'b':
|
||||
v->z = flValue;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int vec3_tostring( lua_State *pState )
|
||||
{
|
||||
char s[ 64 ];
|
||||
Vector *v = lua_getvec3( pState, 1 );
|
||||
|
||||
sprintf( s, "%s %p", VEC3_TYPE, ( void * )v );
|
||||
|
||||
lua_pushstring( pState, s );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_add( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
Vector vResult = v1 + v2;
|
||||
|
||||
lua_newvec3( pState, &vResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_subtract( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
Vector vResult = v1 - v2;
|
||||
|
||||
lua_newvec3( pState, &vResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_multiply( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
Vector vResult = v1 * v2;
|
||||
|
||||
lua_newvec3( pState, &vResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_divide( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
Vector vResult = v1 / v2;
|
||||
|
||||
lua_newvec3( pState, &vResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_length( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
|
||||
float flResult = v1.Length();
|
||||
|
||||
lua_pushnumber( pState, flResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_equal( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
return ( v1 == v2 ? 1 : 0 );
|
||||
}
|
||||
|
||||
|
||||
static int vec3_dot( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState, 2 );
|
||||
|
||||
float flResult = v1.Dot( v2 );
|
||||
|
||||
lua_pushnumber( pState, flResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int vec3_cross( lua_State *pState )
|
||||
{
|
||||
Vector v1 = lua_getvec3ByValue( pState, 1 );
|
||||
Vector v2 = lua_getvec3ByValue( pState,2 );
|
||||
|
||||
Vector vResult = v1,Cross( v2 );
|
||||
|
||||
lua_newvec3( pState, &vResult );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_reg Registrations[] =
|
||||
{
|
||||
{ "__index", vec3_index },
|
||||
{ "__newindex", vec3_newindex },
|
||||
{ "__tostring", vec3_tostring },
|
||||
{ "__add", vec3_add },
|
||||
{ "__sub", vec3_subtract },
|
||||
{ "__mul", vec3_multiply },
|
||||
{ "__div", vec3_divide },
|
||||
{ "__len", vec3_length },
|
||||
{ "__eq", vec3_equal },
|
||||
{ "dot", vec3_dot },
|
||||
{ "cross", vec3_cross },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
LUALIB_API int luaopen_vec3( lua_State *pState )
|
||||
{
|
||||
luaL_newmetatable( pState, VEC3_TYPE );
|
||||
luaL_register( pState, NULL, Registrations );
|
||||
lua_register( pState, VEC3_NAME, vec3_new );
|
||||
|
||||
return 1;
|
||||
}
|
||||
19
vscript/languages/lua/vlua/vec3.h
Normal file
19
vscript/languages/lua/vlua/vec3.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VEC3_H
|
||||
#define VEC3_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "mathlib/vector.h"
|
||||
|
||||
extern int luaopen_vec3(lua_State *L);
|
||||
extern Vector *lua_getvec3(lua_State *L, int i);
|
||||
extern Vector *lua_newvec3( lua_State *L, const Vector *Value );
|
||||
|
||||
#endif // VEC3_H
|
||||
1502
vscript/languages/lua/vlua/vlua.cpp
Normal file
1502
vscript/languages/lua/vlua/vlua.cpp
Normal file
File diff suppressed because it is too large
Load Diff
17
vscript/languages/lua/vlua/vlua.h
Normal file
17
vscript/languages/lua/vlua/vlua.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//========== Copyright <20> 2008, Valve Corporation, All rights reserved. ========
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VLUA_H
|
||||
#define VLUA_H
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
IScriptVM *ScriptCreateLuaVM();
|
||||
void ScriptDestroyLuaVM( IScriptVM *pVM );
|
||||
|
||||
#endif // VLUA_H
|
||||
122
vscript/languages/lua/vlua/vlua.vpc
Normal file
122
vscript/languages/lua/vlua/vlua.vpc
Normal file
@@ -0,0 +1,122 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\..\..\.."
|
||||
$Macro OUTBINDIR "."
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_exe_con_win32_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,..\lua-5.1.4\src\"
|
||||
$PreprocessorDefinitions "$BASE;PROTECTED_THINGS_DISABLE;VLUA_TEST;MSVC"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "vlua"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "..\..\..\..\public\vscript\ivscript.h"
|
||||
$File "..\..\..\..\public\vscript\vscript_templates.h"
|
||||
$File "vlua.cpp"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
// "SQPlus" need exceptions. If commit to squirrel, look into removing that
|
||||
$AdditionalOptions "/EHa"
|
||||
}
|
||||
}
|
||||
}
|
||||
$File "vec3.cpp"
|
||||
$File "vec3.h"
|
||||
}
|
||||
|
||||
$Folder "Lua"
|
||||
{
|
||||
$Folder "lua-5.1.4"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "..\lua-5.1.4\src\lapi.c" \
|
||||
"..\lua-5.1.4\src\lauxlib.c" \
|
||||
"..\lua-5.1.4\src\lbaselib.c" \
|
||||
"..\lua-5.1.4\src\lcode.c" \
|
||||
"..\lua-5.1.4\src\ldblib.c" \
|
||||
"..\lua-5.1.4\src\ldebug.c" \
|
||||
"..\lua-5.1.4\src\ldo.c" \
|
||||
"..\lua-5.1.4\src\ldump.c" \
|
||||
"..\lua-5.1.4\src\lfunc.c" \
|
||||
"..\lua-5.1.4\src\lgc.c" \
|
||||
"..\lua-5.1.4\src\linit.c" \
|
||||
"..\lua-5.1.4\src\liolib.c" \
|
||||
"..\lua-5.1.4\src\llex.c" \
|
||||
"..\lua-5.1.4\src\lmathlib.c" \
|
||||
"..\lua-5.1.4\src\lmem.c" \
|
||||
"..\lua-5.1.4\src\loadlib.c" \
|
||||
"..\lua-5.1.4\src\lobject.c" \
|
||||
"..\lua-5.1.4\src\lopcodes.c" \
|
||||
"..\lua-5.1.4\src\loslib.c" \
|
||||
"..\lua-5.1.4\src\lparser.c" \
|
||||
"..\lua-5.1.4\src\lstate.c" \
|
||||
"..\lua-5.1.4\src\lstring.c" \
|
||||
"..\lua-5.1.4\src\lstrlib.c" \
|
||||
"..\lua-5.1.4\src\ltable.c" \
|
||||
"..\lua-5.1.4\src\ltablib.c" \
|
||||
"..\lua-5.1.4\src\ltm.c" \
|
||||
"..\lua-5.1.4\src\lundump.c" \
|
||||
"..\lua-5.1.4\src\lvm.c" \
|
||||
"..\lua-5.1.4\src\lzio.c" \
|
||||
"..\lua-5.1.4\src\print.c"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$WarningLevel "Level 3 (/W3)"
|
||||
$Detect64bitPortabilityIssues "No"
|
||||
$CompileAs "Default"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "..\lua-5.1.4\src\lapi.h" \
|
||||
"..\lua-5.1.4\src\lauxlib.h" \
|
||||
"..\lua-5.1.4\src\lcode.h" \
|
||||
"..\lua-5.1.4\src\ldebug.h" \
|
||||
"..\lua-5.1.4\src\ldo.h" \
|
||||
"..\lua-5.1.4\src\lfunc.h" \
|
||||
"..\lua-5.1.4\src\lgc.h" \
|
||||
"..\lua-5.1.4\src\llex.h" \
|
||||
"..\lua-5.1.4\src\llimits.h" \
|
||||
"..\lua-5.1.4\src\lmem.h" \
|
||||
"..\lua-5.1.4\src\lobject.h" \
|
||||
"..\lua-5.1.4\src\lopcodes.h" \
|
||||
"..\lua-5.1.4\src\lparser.h" \
|
||||
"..\lua-5.1.4\src\lstate.h" \
|
||||
"..\lua-5.1.4\src\lstring.h" \
|
||||
"..\lua-5.1.4\src\ltable.h" \
|
||||
"..\lua-5.1.4\src\ltm.h" \
|
||||
"..\lua-5.1.4\src\lua.h" \
|
||||
"..\lua-5.1.4\src\luaconf.h" \
|
||||
"..\lua-5.1.4\src\lualib.h" \
|
||||
"..\lua-5.1.4\src\lundump.h" \
|
||||
"..\lua-5.1.4\src\lvm.h" \
|
||||
"..\lua-5.1.4\src\lzio.h"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$File "$SRCDIR\lib\public\mathlib.lib"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user