aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/lobject.c b/lobject.c
index 3dfafde4..67ba2b62 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.70 2001/03/26 14:31:49 roberto Exp $ 2** $Id: lobject.c,v 1.71 2001/10/25 19:14:14 roberto Exp $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,7 +10,6 @@
10#include <stdlib.h> 10#include <stdlib.h>
11#include <string.h> 11#include <string.h>
12 12
13#define LUA_PRIVATE
14#include "lua.h" 13#include "lua.h"
15 14
16#include "ldo.h" 15#include "ldo.h"
@@ -73,12 +72,12 @@ void *luaO_openspaceaux (lua_State *L, size_t n) {
73} 72}
74 73
75 74
76int luaO_str2d (const l_char *s, lua_Number *result) { 75int luaO_str2d (const char *s, lua_Number *result) {
77 l_char *endptr; 76 char *endptr;
78 lua_Number res = lua_str2number(s, &endptr); 77 lua_Number res = lua_str2number(s, &endptr);
79 if (endptr == s) return 0; /* no conversion */ 78 if (endptr == s) return 0; /* no conversion */
80 while (isspace(uchar(*endptr))) endptr++; 79 while (isspace((unsigned char)(*endptr))) endptr++;
81 if (*endptr != l_c('\0')) return 0; /* invalid trailing characters? */ 80 if (*endptr != '\0') return 0; /* invalid trailing characters? */
82 *result = res; 81 *result = res;
83 return 1; 82 return 1;
84} 83}
@@ -88,9 +87,9 @@ int luaO_str2d (const l_char *s, lua_Number *result) {
88#define MAX_VERROR 280 87#define MAX_VERROR 280
89 88
90/* this function needs to handle only '%d' and '%.XXs' formats */ 89/* this function needs to handle only '%d' and '%.XXs' formats */
91void luaO_verror (lua_State *L, const l_char *fmt, ...) { 90void luaO_verror (lua_State *L, const char *fmt, ...) {
92 va_list argp; 91 va_list argp;
93 l_char buff[MAX_VERROR]; /* to hold formatted message */ 92 char buff[MAX_VERROR]; /* to hold formatted message */
94 va_start(argp, fmt); 93 va_start(argp, fmt);
95 vsprintf(buff, fmt, argp); 94 vsprintf(buff, fmt, argp);
96 va_end(argp); 95 va_end(argp);
@@ -98,36 +97,36 @@ void luaO_verror (lua_State *L, const l_char *fmt, ...) {
98} 97}
99 98
100 99
101void luaO_chunkid (l_char *out, const l_char *source, int bufflen) { 100void luaO_chunkid (char *out, const char *source, int bufflen) {
102 if (*source == l_c('=')) { 101 if (*source == '=') {
103 strncpy(out, source+1, bufflen); /* remove first char */ 102 strncpy(out, source+1, bufflen); /* remove first char */
104 out[bufflen-1] = l_c('\0'); /* ensures null termination */ 103 out[bufflen-1] = '\0'; /* ensures null termination */
105 } 104 }
106 else { 105 else {
107 if (*source == l_c('@')) { 106 if (*source == '@') {
108 int l; 107 int l;
109 source++; /* skip the `@' */ 108 source++; /* skip the `@' */
110 bufflen -= sizeof(l_s("file `...%s'")); 109 bufflen -= sizeof("file `...%s'");
111 l = strlen(source); 110 l = strlen(source);
112 if (l>bufflen) { 111 if (l>bufflen) {
113 source += (l-bufflen); /* get last part of file name */ 112 source += (l-bufflen); /* get last part of file name */
114 sprintf(out, l_s("file `...%.99s'"), source); 113 sprintf(out, "file `...%.99s'", source);
115 } 114 }
116 else 115 else
117 sprintf(out, l_s("file `%.99s'"), source); 116 sprintf(out, "file `%.99s'", source);
118 } 117 }
119 else { 118 else {
120 int len = strcspn(source, l_s("\n")); /* stop at first newline */ 119 int len = strcspn(source, "\n"); /* stop at first newline */
121 bufflen -= sizeof(l_s("string \"%.*s...\"")); 120 bufflen -= sizeof("string \"%.*s...\"");
122 if (len > bufflen) len = bufflen; 121 if (len > bufflen) len = bufflen;
123 if (source[len] != l_c('\0')) { /* must truncate? */ 122 if (source[len] != '\0') { /* must truncate? */
124 strcpy(out, l_s("string \"")); 123 strcpy(out, "string \"");
125 out += strlen(out); 124 out += strlen(out);
126 strncpy(out, source, len); 125 strncpy(out, source, len);
127 strcpy(out+len, l_s("...\"")); 126 strcpy(out+len, "...\"");
128 } 127 }
129 else 128 else
130 sprintf(out, l_s("string \"%.99s\""), source); 129 sprintf(out, "string \"%.99s\"", source);
131 } 130 }
132 } 131 }
133} 132}