Remove los.c and lmath.c, and put their functions in the bundled Lua source
This commit is contained in:
parent
05bdda5d05
commit
f2ff542bcb
6 changed files with 61 additions and 107 deletions
|
@ -4,6 +4,11 @@
|
|||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
/***
|
||||
* Math and algorithms.
|
||||
* @module math
|
||||
*/
|
||||
|
||||
#define lmathlib_c
|
||||
#define LUA_LIB
|
||||
|
||||
|
@ -646,6 +651,26 @@ static void setrandfunc (lua_State *L) {
|
|||
luaL_setfuncs(L, randfuncs, 1);
|
||||
}
|
||||
|
||||
/***
|
||||
* Linearly interpolates using the values given.
|
||||
*
|
||||
* Returns `x + (y - x) * z`
|
||||
*
|
||||
* @function lerp
|
||||
* @tparam number x
|
||||
* @tparam number y
|
||||
* @tparam number z
|
||||
*/
|
||||
static int
|
||||
math_lerp(lua_State *L)
|
||||
{
|
||||
double x; /* parameter 1 (number) */
|
||||
|
||||
x = luaL_checknumber(L, 1);
|
||||
lua_pushnumber(L, x + (luaL_checknumber(L, 2) - x) * luaL_checknumber(L, 3));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
||||
|
@ -715,6 +740,7 @@ static const luaL_Reg mathlib[] = {
|
|||
{"floor", math_floor},
|
||||
{"fmod", math_fmod},
|
||||
{"ult", math_ult},
|
||||
{"lerp", math_lerp},
|
||||
{"log", math_log},
|
||||
{"max", math_max},
|
||||
{"min", math_min},
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
||||
/***
|
||||
* Operating system related facilities.
|
||||
* @module os
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
# include <bits/local_lim.h>
|
||||
#else
|
||||
/* assume OpenBSD/NetBSD */
|
||||
# include <sys/syslimits.h>
|
||||
#endif
|
||||
|
||||
#define loslib_c
|
||||
#define LUA_LIB
|
||||
|
||||
|
@ -14,6 +26,7 @@
|
|||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "lua.h"
|
||||
|
@ -403,6 +416,26 @@ static int os_exit (lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* Returns the system hostname.
|
||||
*
|
||||
* @function hostname
|
||||
* @usage local hostname = os.hostname()
|
||||
*/
|
||||
static int
|
||||
os_hostname(lua_State *L)
|
||||
{
|
||||
char *buffer;
|
||||
|
||||
buffer = malloc(HOST_NAME_MAX * sizeof(char *));
|
||||
|
||||
gethostname(buffer, HOST_NAME_MAX); /* get hostname */
|
||||
lua_pushstring(L, buffer);
|
||||
free(buffer);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg syslib[] = {
|
||||
{"clock", os_clock},
|
||||
|
@ -411,6 +444,7 @@ static const luaL_Reg syslib[] = {
|
|||
{"execute", os_execute},
|
||||
{"exit", os_exit},
|
||||
{"getenv", os_getenv},
|
||||
{"hostname", os_hostname},
|
||||
{"remove", os_remove},
|
||||
{"rename", os_rename},
|
||||
{"setlocale", os_setlocale},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue