The Small language forum - message archive for 2002
[261] Passing strings to public function
Posted By Gilad Novik on January 03, 2002 at 03:35:47:Is it possible to pass a string while calling a public function ?
char szTest[]="Test";
amx_Exec(&m_AMX,&nRet,nIndex,1,szTest);
[262] Unknown Char symbol
Posted By Darren Dyke on January 03, 2002 at 17:47:27:Ok, i know in programming languages, you can use a symbol in place of an unknown char, like for example in VB we use the * and the # for numbers... i was wondering what was that in small...
Thank You,
Darren
[264] Re: Passing strings to public function
Posted By Thiadmer Riemersma on January 04, 2002 at 09:29:56:In Reply to: Passing strings to public function posted byGilad Novik on January 03, 2002 at 03:35:47:
: Is it possible to pass a string while calling a public function ?
Yes, but you have to allocate memory for the string inside the abstract machine first and pass the address of that memory block to amx_Exec(). To allocate memory, use the function amx_Allot(); to release the memory afterwards, use amx_Release(). Message number 167 (see the link below) has a longer explanation of amx_Allot() and amx_Release(). By the way, the documentation errors that the message mentions have been corrected by now.
Thiadmer
[265] Re: Unknown Char symbol
Posted By Thiadmer Riemersma on January 04, 2002 at 09:36:06:In Reply to: Unknown Char symbol posted byDarren Dyke on January 03, 2002 at 17:47:27:
: Ok, i know in programming languages, you can use a symbol in place of an unknown char, like for example in VB we use the * and the # for numbers... i was wondering what was that in small...
You are probably referring to either input parsing (reading values/messages that the user types on the keyboard) or to some kind of file parsing. Small does those things with "native functions". None of the native functions that I made for the general purpose Small toolkit has wildcards.
But if you are asking this question, it might be that you are using a particular implementation of Small. Could you elaborate on what you are using and what you are trying to achieve?
Thiadmer
[266] Re: Unknown Char symbol
Posted By Darren Dyke on January 04, 2002 at 19:30:10:In Reply to: Re: Unknown Char symbol posted byThiadmer Riemersma on January 04, 2002 at 09:36:06:
Yes, well i am using small to make a pluging for admin mod. What i want this plugin to do is scan for files on a clients computer... i think it can be done, but i need a wild card to search for ogc.***.exe as the " * " the wild card
[267] Re: Unknown Char symbol
Posted By Thiadmer Riemersma on January 07, 2002 at 02:47:44:In Reply to: Re: Unknown Char symbol posted byDarren Dyke on January 04, 2002 at 19:30:10:
: Yes, well i am using small to make a pluging for admin mod. [...]
I do not know much about the admin mod myself. If you do not get an answer from someone more knowledgeable about the admin mod, you may want to ask your question at the admin mod forums (if you haven't done so already).
Thiadmer
[268] combined comparison of float
Posted By chop on January 07, 2002 at 13:30:43:Hi. I encountered the probrem below.
new float:f=0.0;
if( -2.0<=f<=-1.0 ){ return f-(-2.0); } // tag mismatch occured
if( -2.0<=f && f<=-1.0 ){ return f-(-2.0); } // OK
combined comparison of float number seems not to be handled properly.
[269] variable in different file
Posted By chop on January 07, 2002 at 22:37:17:Hi. I encountered the probrem below.
----- menu.inc -----
menu_loop()
{
for( new i=0 ; i<item_num ; i++ )
{
...
}
}
----- endof menu.inc -----
----- page.sma -----
#include "menu.inc"
new item_num = 10;
main()
{
menu_loop();
}
----- endof page.sma -----
There are no compile time error, but,
variable [ item_num ] cannot be accessed correctly.
The value is undefined.
[270] Re: combined comparison of float
Posted By Thiadmer Riemersma on January 08, 2002 at 02:47:21:In Reply to: combined comparison of float posted bychop on January 07, 2002 at 13:30:43:
: new float:f=0.0;
: if( -2.0<=f<=-1.0 ){ return f-(-2.0); } // tag mismatch occured
: if( -2.0<=f && f<=-1.0 ){ return f-(-2.0); } // OK
I will look into this. Thank you for the bug report.
Thiadmer
[271] Re: variable in different file
Posted By Thiadmer Riemersma on January 08, 2002 at 02:56:16:In Reply to: variable in different file posted bychop on January 07, 2002 at 22:37:17:
: ----- menu.inc -----
: menu_loop()
: {
: for( new i=0 ; i<item_num ; i++ )
: {
: ...
: }
: }
: ----- endof menu.inc -----
:
: ----- page.sma -----
: #include "menu.inc"
: new item_num = 10;
:
: main()
: {
: menu_loop();
: }
: ----- endof page.sma -----
: There are no compile time error, but, variable [ item_num ] cannot be accessed correctly. The value is undefined.
I will look into this. There should be a compile error: variables must be declared before use. In your case, through the order of the #include "menu.inc" and the new item_num = 10; lines, the function menu_loop() uses the variable item_num before it is declared. (So a quick fix is to swap those two lines.)
Thiadmer
[272] Re: variable in different file
Posted By chop on January 08, 2002 at 12:14:31:In Reply to: Re: variable in different file posted byThiadmer Riemersma on January 08, 2002 at 02:56:16:
: I will look into this. There should be a compile error: variables must be declared before use. In your case, through the order of the #include "menu.inc" and the new item_num = 10; lines, the function menu_loop() uses the variable item_num before it is declared. (So a quick fix is to swap those two lines.)
I swapped these two lines, and succeeded.
Thank you very much.
[273] Problem, please help
Posted By Dave Sims on January 08, 2002 at 22:12:43:Hi, I wrote a native function called CallFunction which allows you to call public functions in other scripts, you specify the script you want call from (an entity in this case), the function name and the list of parameters (as an ellipsis).
Heres an example:
file1
CallFunction("file2", "MyFunction", 1,2,3,4,5);
file2
public MyFunction(a,b,c,d,e)
{
}
The first file calls a function called MyFunction in the second file, passing 5 normal parameters. This works.
However, if you try to pass an array to the function it doesnt work, I tried to pass a string as a parameter and it just came out blank.
file1
CallFunction("file2", "MyFunction2", "string param");
file2
public MyFunction2( param[] )
{
// Contents of param are blank, when it should be "string param"
}
I dont know why this is happening, please help me to get it working, the C++ code for the CallFunction native function is below:
//-------------------------------------------------------------
// Name: CallFunction("entid", isLibrary, "funcname", ... )
//-------------------------------------------------------------
static cell AMX_NATIVE_CALL CallFunction(AMX *amx, cell *params)
{
char szString[ENT_STRING_MAX];
int wIndex;
cell ret;
int wNumParam = (int)(params[0]/sizeof(cell))-3;
// Get the String from the third Param
GetStringParam(amx, params[3], szString);
CEntity* pTemp = GetEntity(amx, params);
if (pTemp)
{
if (pTemp->GetAMX())
{
amx_FindPublic(pTemp->GetAMX(), szString, &wIndex);
amx_Execv(pTemp->GetAMX(), &ret, wIndex, wNumParam, params+4);
return ret;
}
}
// Call failed
return -1;
}
[274] Re: Problem, please help
Posted By Dave Sims on January 09, 2002 at 22:15:22:In Reply to: Problem, please help posted byDave Sims on January 08, 2002 at 22:12:43:
I see from reading other posts that I can do this, I just have to allocate memory for the strings in the abstract machine I am calling using amx_allot.
Now I have another problem, how can I tell which parameters are arrays and which are normal cells? becuase I will have to allocate memory for the arrays but not the cells, but each parameter could be either.
[275] Re: Problem, please help
Posted By Thiadmer Riemersma on January 11, 2002 at 04:03:39:In Reply to: Re: Problem, please help posted byDave Sims on January 09, 2002 at 22:15:22:
: Now I have another problem, how can I tell which parameters are arrays and which are normal cells? becuase I will have to allocate memory for the arrays but not the cells, but each parameter could be either.
You need a kind of "format string" parameter that gives the types of all subsequent parameters. This is how I implemented the "calldll()" function in the AMX DLLs (it is described in the manual, at page 65).
Thiadmer
[276] networking?
Posted By Singh on January 11, 2002 at 06:08:32:is there a library which will provide me some networking functions?
I also saw a post about executing external commands, and the reply was about creating a new function which executes the external command.. It still doesnt explain howto execute the external command, maybe some source code would help?
TIA
-Jessi
[277] Anyone willing to write me a script?
Posted By Brian Bremer on January 13, 2002 at 16:41:45:Hello.
Unfortunately I do not know small. I plan to learn the language but currently a problem exists that I would like to see resolved soon as possible. Servers for a game called half-life use a collection of files to extend the servers cappabilites called admin mod. Admin mod scripts are written in small language which is why I am here. Recently an exploit was found that allows users to make somthing similar to denial of service attack on the server. This happens when a variable on a client is set to this "Nick%%%%%%%%%%%%%%%%%%%%%%%%%" The Nick part is not the problem, but the percent signs following the word Nick is. It causes problems on clients that are connected to server, the exploit itself is intended to ruin the game.
If somone would be willing, or knows somone willing, to write a small script to stop this problem I would appreciate this. The extensions for small pertaining to half-life are here http://www.adminmod.org/ascript/functions.html
I know what needs to be done far as the scripting relative to the game, but as I said before I do not know enough about small to write my own script to make it work. Please contact me if interested.
Thank You
email: clantia@earthlink.net
icq: 10519381
[278] Re: Problem, please help
Posted By Dave Sims on January 13, 2002 at 16:44:35:In Reply to: Re: Problem, please help posted byThiadmer Riemersma on January 11, 2002 at 04:03:39:
Hi,
Im still having problems using this, I dont understand how to use amx_Allot properly.
Look back to my first post in this thread, supppose I wanted to pass a string parameter to the CallFunction function, I know that I have to allocate memory in the new AMX structure (the one I am calling which has the public function).
How do I use amx_Allot to allocate memory for string parameters passed to CallFunction? please could you give some example code or somthing?
Once ive allocated memory for the string parameters, what do I pass to amx_Execv?
I just find this all very confusing, some example code would be great as it would be a good starting point.
Thanks.
[279] changes for multibyte-charactor
Posted By chop on January 14, 2002 at 14:43:52:Hi, my project is using Small, and UTF-8 for multibyte-charactor.
Because of default Small mistakes "packed mutibyte" charactor for
"unpacked", I patched to amx.c.
If first charactor of packed string was multibyte,
it makes *cstr < 0.
before: if (*cstr>UCHAR_MAX) {
after : if ((ucell)*cstr>UCHAR_MAX) {
[280] Re: Anyone willing to write me a script?
Posted By Jim Bellinger on January 15, 2002 at 22:21:34:In Reply to: Anyone willing to write me a script? posted byBrian Bremer on January 13, 2002 at 16:41:45:
: Hello.
: Unfortunately I do not know small. I plan to learn the language but currently a problem exists that I would like to see resolved soon as possible. Servers for a game called half-life use a collection of files to extend the servers cappabilites called admin mod. Admin mod scripts are written in small language which is why I am here. Recently an exploit was found that allows users to make somthing similar to denial of service attack on the server. This happens when a variable on a client is set to this "Nick%%%%%%%%%%%%%%%%%%%%%%%%%" The Nick part is not the problem, but the percent signs following the word Nick is. It causes problems on clients that are connected to server, the exploit itself is intended to ruin the game.
: If somone would be willing, or knows somone willing, to write a small script to stop this problem I would appreciate this. The extensions for small pertaining to half-life are here http://www.adminmod.org/ascript/functions.html
: I know what needs to be done far as the scripting relative to the game, but as I said before I do not know enough about small to write my own script to make it work. Please contact me if interested.
: Thank You
: email: clantia@earthlink.net
: icq: 10519381
Where can one get the basic script that handles login? I'd be glad to modify it a bit to get rid of %s if that's all it needs, heh. Sounds simple.
[281] sdbg.c bug
Posted By chop on January 20, 2002 at 04:38:20:in break_set of sdbg.c
/* find an empty spot */
for (index=0; index<MAXBREAKS && breakpoints[index].type!=BP_NONE; index++)
/* nothing */
lacks semicolon.
[282] I am trying to find the small v1.8.1 download link
Posted By matt on January 21, 2002 at 14:55:04:
where the heck is it!!! I downloaded the smalltool kit thinking I could install it for Linux ..
[283] Re: Problem, please help
Posted By Thiadmer Riemersma on January 23, 2002 at 08:47:30:In Reply to: Re: Problem, please help posted byDave Sims on January 13, 2002 at 16:44:35:
I have put an example C program (a replacement for the srun.c from the Small manual) below, plus a script file with a public function that accepts a string. I am in the process of documenting it in the manual, but it may take a few weeks still until I have a new release ready. I hope you can find the appropriate information with the example and the Small manual.
If you compile the C program and the small script, you can run the script with:
srun rot13.amx rot13 hello-world
The modified srun.c (see the main() function)
#include <stdio.h>
#include <stdlib.h> /* for exit() */
#include <string.h> /* for memset() (on some compilers) */
#include "amx.h"
size_t srun_ProgramSize(char *filename)
{
FILE *fp;
AMX_HEADER hdr;
if ((fp=fopen(filename,"rb")) == NULL)
return 0;
fread(&hdr, sizeof hdr, 1, fp);
fclose(fp);
amx_Align16(&hdr.magic);
amx_Align32((unsigned long*)&hdr.stp);
return (hdr.magic==AMX_MAGIC) ? (size_t)hdr.stp : 0;
}
int srun_LoadProgram(AMX *amx, char *filename, void *memblock)
{
FILE *fp;
AMX_HEADER hdr;
if ((fp = fopen(filename, "rb")) == NULL )
return AMX_ERR_NOTFOUND;
fread(&hdr, sizeof hdr, 1, fp);
amx_Align32((unsigned long *)&hdr.size);
rewind(fp);
fread(memblock, 1, (size_t)hdr.size, fp);
fclose(fp);
memset(amx, 0, sizeof *amx);
return amx_Init(amx, memblock);
}
static void ErrorExit(char *message, int errorcode)
{
printf(message, errorcode);
printf("\n");
exit(1);
}
int main(int argc,char *argv[])
{
extern AMX_NATIVE_INFO console_Natives[];
extern AMX_NATIVE_INFO core_Natives[];
size_t memsize;
void *program;
AMX amx;
int index, err;
cell amx_addr, *phys_addr;
char output[128];
if (argc != 4)
ErrorExit("Usage: srun4 [filename] [function] [param]", 0);
if ((memsize = srun_ProgramSize(argv[1])) == 0)
ErrorExit("File open error", 0);
program = malloc(memsize);
if (program == NULL)
ErrorExit("Failed to allocate memory", 0);
err = srun_LoadProgram(&amx, argv[1], program);
if (err != AMX_ERR_NONE)
ErrorExit("Load error %d (invalid file format or version)", err);
amx_Register(&amx, console_Natives, -1);
err = amx_Register(&amx, core_Natives, -1);
if (err != AMX_ERR_NONE)
ErrorExit("The program uses unavailable native functions", 0);
err = amx_FindPublic(&amx, argv[2], &index);
if (err != AMX_ERR_NONE)
ErrorExit("Public function is not present", 0);
err = amx_Allot(&amx, strlen(argv[3]) + 1, &amx_addr, &phys_addr);
if (err != AMX_ERR_NONE)
ErrorExit("Failed to allocate AMX memory", 0);
amx_SetString(phys_addr, argv[3], 0);
err = amx_Exec(&amx, NULL, index, 1, amx_addr);
if (err != AMX_ERR_NONE)
printf("Run time error %d on line %ld\n", err, amx.curline);
amx_GetString(output, phys_addr);
amx_Release(&amx, amx_addr);
printf("%s returns %s\n", argv[1], output);
free(program);
return 0;
}The modified rot13.sma
public rot13(string[])
{
for (new index = 0; string[index]; index++)
if ('a' <= string[index] <= 'z')
string[index] = (string[index] - 'a' + 13) % 26 + 'a'
else if ('A' <= string[index] <= 'Z')
string[index] = (string[index] - 'A' + 13) % 26 + 'A'
}
[284] Re: changes for multibyte-charactor
Posted By Thiadmer Riemersma on January 23, 2002 at 08:51:33:In Reply to: changes for multibyte-charactor posted bychop on January 14, 2002 at 14:43:52:
: before: if (*cstr>UCHAR_MAX) {
: after : if ((ucell)*cstr>UCHAR_MAX) {
I will correct this. You found this bug in amx_StrLen(), right?
Thiadmer
[285] Re: sdbg.c bug
Posted By Thiadmer Riemersma on January 23, 2002 at 08:53:27:In Reply to: sdbg.c bug posted bychop on January 20, 2002 at 04:38:20:
: in break_set of sdbg.c
: /* find an empty spot */
: for (index=0; index<MAXBREAKS && breakpoints[index].type!=BP_NONE; index++)
: /* nothing */
: lacks semicolon.
Oops. Thank you for the notice. I will correct this.
Thiadmer
[286] Re: I am trying to find the small v1.8.1 download link
Posted By Thiadmer Riemersma on January 23, 2002 at 08:56:49:In Reply to: I am trying to find the small v1.8.1 download link posted bymatt on January 21, 2002 at 14:55:04:
The current version is 1.8.2 and that is also the only version that I offer for download (http://www.compuphase.com/smallkit.zip). I do not keep archives of older versions. Maybe somebody else still has it.
That said, I am unaware of any problems of version 1.8.2 specific to Linux.
Thiadmer
[287] Re: changes for multibyte-charactor
Posted By chop on January 23, 2002 at 15:30:32:In Reply to: Re: changes for multibyte-charactor posted byThiadmer Riemersma on January 23, 2002 at 08:51:33:
: I will correct this. You found this bug in amx_StrLen(), right?
amx_StrLen / amx_SetString / amx_GetString
/ printstring / amx_StrPack / amx_StrUnpack
have a same bug.
and, in pdf manual, ispacked sample has a same bug too.
[288] verify_addr
Posted By chop on January 27, 2002 at 09:39:56:
strpack and strunpack use function [verify_addr],
like this,
needed=(len+sizeof(cell)-1)/sizeof(cell);
if (verify_addr(amx,(cell)(params[1]+needed))!=AMX_ERR_NONE)
The unit of variable [needed] is cell.
But, [verify_addr]'s argument is by byte.(is it right?)
it seems to be bug.
One more,
I think, calculation of [needed] should be
needed=( ( len + 1 ) +sizeof(cell)-1)/sizeof(cell);
[289] Visual Basic
Posted By Thraka on January 29, 2002 at 13:58:42:
How can I add this scripting language to visual basic?
[290] Re: verify_addr
Posted By Thiadmer Riemersma on January 30, 2002 at 10:36:04:In Reply to: verify_addr posted bychop on January 27, 2002 at 09:39:56:
: it seems to be bug.
I think it is, too. I will verify the behaviour more closely and correct it if needed.
: One more,
: I think, calculation of [needed] should be
: needed=( ( len + 1 ) +sizeof(cell)-1)/sizeof(cell);
You are correct, this is an error.
Thank you for the reports.
Thiadmer
[291] Re: Visual Basic
Posted By Thiadmer Riemersma on January 30, 2002 at 10:37:25:In Reply to: Visual Basic posted byThraka on January 29, 2002 at 13:58:42:
: How can I add this scripting language to visual basic?
The easiest way is to use the AMX DLLs (like AMX32.DLL). You must use amx_Execv() instead of amx_Exec().
Thiadmer
[292] An idea to small programmers
Posted By Gilad Novik on January 31, 2002 at 08:36:41:Since small support a single type (32bit variables), you can extend it using some kind of garbage collection.
In my application, I am using small to manipulate an html document. Since all the objects of the documents are interfaces derives from IUnknown, I am using an array of IUnknown pointers.
CArray<IUnknown*,IUnknown*> Garbage;
void ThrowGarbage()
{ for (int nIndex=Garbage.GetSize()-1;nIndex>=0;nIndex--)
Garbage[nIndex]->Release();
Garbage.RemoveAll();
}
When I get a pointer to an interface, I add it to the array, and pass its index to the function. This way, I don't need to handle the memory allocation from the small script itself.
for example:
// The next function will return an ID of the document object or -1 if an error occurrd
cell AMX_NATIVE_CALL GetDocumentID(AMX *Amx,cell *Params)
{ IHTMLDocument2 *pDocument=NULL;
... // Here we get a pointer to the document
return (pDocument ? Garbage.Add(pDocument) : -1);
}
in the script, we can use:
new nDocument; nDocument=GetDocumentID(); if (nDocument==-1) // Let's check for errors return 0;
To use the object in another function, we can use the following sample:
cell AMX_NATIVE_CALL GetDocumnentTitle(AMX *Amx,cell *Params)
{ if (Params[1]==-1)
return 0;
IHTMLDocument2 *pDocument=(IHTMLDocument2*)Garbage[Params[1]];
... // Now we can use the pDocument object)
return 1;
}
[293] A Little notice
Posted By Gilad Novik on January 31, 2002 at 08:40:01:In Reply to: An idea to small programmers posted byGilad Novik on January 31, 2002 at 08:36:41:
The forum engine stripped out a line in the code. The 'Garbage' variable contains elements of type IUnknown*
[294] Re: networking?
Posted By Gilad Novik on January 31, 2002 at 08:53:07:In Reply to: networking? posted bySingh on January 11, 2002 at 06:08:32:
: is there a library which will provide me some networking functions?
: I also saw a post about executing external commands, and the reply was about creating a new function which executes the external command.. It still doesnt explain howto execute the external command, maybe some source code would help?
: TIA
: -Jessi
Let's say you want to create a function called Execute.
In the small header file, you need to declare:
native Execute(const szCommand[]);
Next, you create the function itself:
cell AMX_NATIVE_CALL Execute(AMX *Amx,cell *Params)
{
char szCommand[1024]={0};
cell *pCell=NULL;
if (amx_GetAddr(Amx,Params[1],&pCell)==AMX_ERR_NONE && amx_GetString(szCommand,pCell)==AMX_ERR_NONE)
return (int)ShellExecute(NULL,NULL,szCommand,NULL,NULL,SW_SHOW);
return -1;
}
Now, you can call it from the small script:
Execute("c:\\index.html");
[295] Re: A Little notice
Posted By Thiadmer Riemersma on January 31, 2002 at 11:19:52:In Reply to: A Little notice posted byGilad Novik on January 31, 2002 at 08:40:01:
: The forum engine stripped out a line in the code.
It is very annoying when that happens. Note that the forum supports HTML as well, so you can format your message in HTML and paste it into the message. The link below is to a HTML formatted message on this forum.
Thiadmer
[296] Interfacing with MS com objects
Posted By Mell on January 31, 2002 at 16:05:24:
is there anyway to interact with com objects like ADODB.connect for data base stuff?
[297] Re: Interfacing with MS com objects
Posted By Thiadmer Riemersma on February 01, 2002 at 05:29:52:In Reply to: Interfacing with MS com objects posted byMell on January 31, 2002 at 16:05:24:
: is there anyway to interact with com objects like ADODB.connect for data base stuff?
You need a set of "native functions" that manage COM instances. I do not have such an interface. As an aside, I know that at least one Small user created an ODBC interface.
Thiadmer
[298] Re: Visual Basic
Posted By Thraka on February 01, 2002 at 15:02:24:In Reply to: Re: Visual Basic posted byThiadmer Riemersma on January 30, 2002 at 10:37:25:
: : How can I add this scripting language to visual basic?
: The easiest way is to use the AMX DLLs (like AMX32.DLL). You must use amx_Execv() instead of amx_Exec().
: Thiadmer
I cannot register the dll and i cannot find it when trying to add it to my project.. Does this even work with VB?
[299] Re: OpenBSD trick
Posted By squee on February 02, 2002 at 13:48:44:In Reply to: Re: OpenBSD trick posted byThiadmer Riemersma on December 03, 2001 at 03:25:38:
Will this trick also work for OSX? (since its a BSD derivative?)
or has anyone gotten it to work on OSx?
-T
: : With this trick small toolkit should work on openbsd machines.. just consider it as linux
: : In sclinux.h :
: : #if defined(__OpenBSD__)
: : #define __BYTE_ORDER BYTE_ORDER
: : #define __LITTLE_ENDIAN LITTLE_ENDIAN
: : #define __BIG_ENDIAN BIG_ENDIAN
: : #endif
: Thank you. I will add this section to sclinux.h.
: Thiadmer
[300] Small in Delphi
Posted By Luke Croteau on February 03, 2002 at 02:57:44:Has anybody successfully used Small with the Delphi compilers?
I was thinking of adding simple processing to my application, and as I have had experience with Adminmod, I first thought of small as a good extender.
Any resources would be appreciated,
Luke
[301] Re: Visual Basic
Posted By Thiadmer Riemersma on February 04, 2002 at 04:48:06:In Reply to: Re: Visual Basic posted byThraka on February 01, 2002 at 15:02:24:
: I cannot register the dll and i cannot find it when trying to add it to my project. [...]
It sounds like you want a type library (a .TLB file). There isn't one yet (I will check whether I can make one).
The alternative to a type library is a module (.BAS) with the declarations of all DLL functions. That is, lines like:
Declare Function amx_Init Lib "amx32.dll" (ByVal amx As String, ByVal program As String) As Integer
: Does this even work with VB?
I have not tried to use it with VB. The main impression is that it should work, but there will be a few rough edges. For example, there are a few C/C++ structures that need to be translated carefully to Visual Basic to avoid alignment problems. Also, I do not know what is the best choice for the data type that keeps the program loaded from disk. In my "Declare" above, I have used "String", there may be problems using a "string" to store binary data.
Thiadmer
[302] Re: Visual Basic
Posted By Thraka on February 04, 2002 at 12:35:24:In Reply to: Re: Visual Basic posted byThiadmer Riemersma on February 04, 2002 at 04:48:06:
: : I cannot register the dll and i cannot find it when trying to add it to my project. [...]
: It sounds like you want a type library (a .TLB file). There isn't one yet (I will check whether I can make one).
: The alternative to a type library is a module (.BAS) with the declarations of all DLL functions. That is, lines like:
: Declare Function amx_Init Lib "amx32.dll" (ByVal amx As String, ByVal program As String) As Integer
: : Does this even work with VB?
: I have not tried to use it with VB. The main impression is that it should work, but there will be a few rough edges. For example, there are a few C/C++ structures that need to be translated carefully to Visual Basic to avoid alignment problems. Also, I do not know what is the best choice for the data type that keeps the program loaded from disk. In my "Declare" above, I have used "String", there may be problems using a "string" to store binary data.
: Thiadmer
Try using a Variant. If you got a working one for VB, this would hit the gaming community very well. VB has a nice sized (and growing) game programming community. We all have do NOT have a professional scripting language. We need one badly.
[303] Implimentation...
Posted By Thraka on February 04, 2002 at 12:38:11:
So do you just creat scripts... then compile them, then your program that you're using calls functions that load the compiled scripts from a specified location?
[304] Small on OSX?
Posted By squeej on February 05, 2002 at 21:18:17:Does anyone have an implementation of Small running on OSX?
regards
T
[305] Compiler Difficulty
Posted By James Abney on February 07, 2002 at 17:28:35:Hello to all,
I'm having a minor difficulty with the Small compiler.
In the code below, the type-o in the print statement, due to case sensitivity, actually causes the compiler to crash, instead of reporting the error. This happens if you pass any undefined name to the print function; it happened with printf as well (i am using the srun utility that came with small).
#include <console>
#define GROUPSIZE 30
main()
{
new Group[GROUPSIZE] = {1,2,3,4,5,6,7}
print(group)
}
Has anyone seen this?
Thanks,
James Abney
[306] Re: Compiler Difficulty
Posted By Thiadmer Riemersma on February 08, 2002 at 06:54:12:In Reply to: Compiler Difficulty posted byJames Abney on February 07, 2002 at 17:28:35:
: In the code below, the type-o in the print statement, due to case sensitivity, actually causes the compiler to crash, instead of reporting the error.
I will look into this. Thank you for the bug report.
Thiadmer
[307] speed
Posted By cody on February 15, 2002 at 11:08:05:hi,
im thinking about what scripting language i should use for my game.
i have used lua quite long but small looks very interessting too.
my question is: how fast is small compared to lua? i think its faster... but how much? are there any performance benchmarks?
[308] Re: speed
Posted by Thiadmer Riemersma on February 19, 2002 at 04:45:45:In Reply to: speed posted bycody on February 15, 2002 at 11:08:05:
Comparing Small with Lua
In the spirit of "Lies, Damned lies, and Benchmarks", here are a few comparisons between Small and Lua. Before anything else, I would like to quote the paper "Timing Trials, or, the Trials of Timing: Experiments with Scripting and User-Interface Languages" by Kernighan and Van Wyk, which says in its abstract: "[...] if there is a single clear conclusion, it is that no benchmark result should ever be taken at face value."
| Benchmark | Lua (seconds) | Small (seconds) |
| Sieve | 59 | 13.5 |
| Fibonacci | 14 | 14 |
The scripts for these benchmarks are below. I took the Lua scripts from an archive that has many of these benchmarks in many (scripting) languages. I took just the "Sieve of Eratosthenes" and "Fibonacci numbers" for the moment, because I know these algorithms well. All timings were done on a PC with an Intel Pentium 100 MHz, running Windows98.
To compile and run the Lua scripts, I used the pre-compiled Win32 distribution of Lua 4.0 with the command lines:
luac -o sieve.out -s sieve.lua lua sieve.out
To compile the Small scripts, I used the precompiled Win32 distribution of Small 1.8.3 with the command lines
sc -d0 sieve srun sieve.amx
Are these the best achievable timings? No. I am unaware of optimized Lua virtual machines, but for Small there is Marc Peter's Just-In-Time compiler which is significantly faster. The "sieve.sma" program completes in 5.0 seconds when run with "srun_jit.exe" instead of "srun.exe" --more than ten times faster than the Lua version.
Are these timings fair? Probably not. Note the command line options for the compilers. I used -s for Lua to strip symbolic information and -d0 for Small to compile without debugging information. I haven't tested if Lua's -s switch influences the performance, but Small's -d0 switch certainly does... the -d0 switch also removes array bounds checking and any calls to a debugging hook. With switch -d1 (which is also the default), the execution time of "sieve.sma" raises to 57 seconds --about the same performance as Lua. Then again, the default run-time of Small, "srun.exe" does have a debugging hook (even if it has no purpose for these tests), and this hook eats up time. The default run-time of Small is not really appropriate to perform benchmarks with. The default run-time of Lua probably isn't either.
To finish, a few more notes:
- I was surprised by the relative poor performance of Small in the Fibonacci benchmark. My guess is that this is caused by the stack checking that Small does at the prologue of every function. This does not harm much in larger functions, but it does harm in smaller functions. The Fibonacci function happens to be tiny. That said, this particular benchmark was probably made specifically to test the function call overhead. I tested my assumption by also running "fibo.sma" with the JIT (which does not do stack checking); it ran in 1.3 seconds.
- The machine matters. I also ran the Sieve of Eratosthenes tests on an AMD Athlon (I forgot the clock speed; it is probably 1 GHz). On that machine, Small was about twice as fast as Lua when sieve.sma was compiled with the
-d1option and a bit over 5 times as fast when using option-d0. I have no idea as to why this so; Small is not specifically optimized for the Athlon. Perhaps Small is better able to benefit from the improved branch prediction in newer processors, perhaps proper alignment of data and opcodes matters more now than it did with the Pentium...
Sieve of Eratosthenes, Lua version
-- $Id: sieve.lua,v 1.10 2001/07/11 17:58:14 doug Exp $
-- http://www.bagley.org/~doug/shootout/
--
-- Roberto Ierusalimschy pointed out the for loop is much
-- faster for our purposes here than using a while loop.function sieve(num)
local flags = {}
for num=num,1,-1 do
count = 0
for i=2,8192 do
flags[i] = 1
end
for i=2,8192 do
if flags[i] == 1 then
for k=i+i, 8192, i do
flags[k] = 0
end
count = count + 1
end
end
end
endNUM = 500 -- tonumber((arg and arg[1])) or 1
count = 0
sieve(NUM)
write("Count: ", count, "\n")
Sieve of Eratosthenes, Small version
#include <console>
#pragma dynamic 10240new count
sieve(num)
{
const max_primes = 8192
new series[max_primes] = { true, ... }
while (--num >= 0)
{
count = 0
for (new i = 2; i <= max_primes; ++i)>
if (series[i])
{
/* filter all multiples of this "prime" from the list */
for (new j = 2 * i; j <= max_primes; j +=i)>
series[j] = false
count++
}
}
}main()
{
new NUM = 500
count = 0
sieve(NUM)
printf("Count: %d^n", count)
}
Fibonacci numbers, Lua version
-- $Id: fibo.lua,v 1.2 2000/12/24 19:10:50 doug Exp $
-- http://www.bagley.org/~doug/shootout/function fib(n)
if (n < 2) then return(1) end
return( fib(n-2) + fib(n-1) )
endN = 30 -- tonumber((arg and arg[1])) or 1
write(fib(N), "\n")
Fibonacci numbers, Small version
#include <console<fib(n)
return (n < 2) ? 1 : fib(n-2) + fib(n-1)main()
{
new N = 30
printf("%d^n", fib(N))
}
[309] Native functions in C++
Posted By John Gillespie on February 26, 2002 at 17:32:43:Thiadmer
Thanks for your work on Small, very nice. I've ported the abstraction machine to the Pocket PC and it is running scripts, I'll upload the source to you when I've cleaned it up.
My question is around declaring a native function for small that is also a C++ method. Is this possible and if so are there any examples of this?
What is happening is that when I declare the external_Natives structure the compiler does not recognize the function, actual error message is -
<<>>
error C2440: 'initializing' : cannot convert from '' to 'long (__cdecl *)(struct __amx *,long *)'
None of the functions with this name in scope match the target type
<<>>
This error happens at the line below containing
AMX_NATIVE_INFO external_Natives[]=
{
{"squared", n_squared},
{0,0} //terminator
};
<<<>>>
My code (snipped)...
//native call definition as method of the class CStrike
cell AMX_NATIVE_CALL CStrike::n_squared(AMX *amx, cell *params)
{
cell result=0;
//squared (value)
//params[1]=value
result=params[1]*params[1];
return result;
}
...
CStrike::CStrike(void)
{
cell cresult;
CString sResult;
AMX *testamx;
cell *testparams;
m_scriptInit=new CScript(TEXT("\\test.amx"));
AMX_NATIVE_INFO external_Natives[]=
{
{"squared", n_squared},
{0,0} //terminator
};
if (m_scriptInit->GetValid())
{
m_scriptInit->RegisterNatives(external_Natives);
cresult=m_scriptInit->Run();
sResult.Format(TEXT("Run Result is %d"),cresult);
MessageBox(NULL,sResult,TEXT("Debug"),MB_OK);
}
else
MessageBox(NULL,TEXT("Failed to load script based on test.amx"),TEXT("Debug"),MB_OK);
}
[310] Re: Native functions in C++
Posted By Bjoern Graf on February 27, 2002 at 20:18:36:In Reply to: Native functions in C++ posted byJohn Gillespie on February 26, 2002 at 17:32:43:
: Thiadmer
Sorry, I'm not Thiadmer ;)
: My question is around declaring a native function for small that is also a C++ method. Is this possible and if so are there any examples of this?
You need to define the class functions as static to be able to provide them at link time.
Hope this helps,
Bjørn.
[311] best way to share data between small and C
Posted By Han Cicimen on March 05, 2002 at 08:06:13:
1) As far as I understand the Small is optimised for 32 bit platforms. When ý check the amx.c I noticed malloc used which limits the data and program size to 64K limit. I wonder if anybody use amx program sizes bigger than 64 K for 16 Bit dos?
2) In my new application I have to transfer data between native C to Small. There are lots of data and I plan to simplify the system for the script programmer and I plan to use one big array in native C:
long Datas[8192];
Let say in Array Datas there some spesific data which "Small" and C can use.
I do not want to open "Datas" array in "Small" program. What will be the best method to share data between native C and "Small"?
HAN
[312] Re: best way to share data between small and C
Posted By Thiadmer Riemersma on March 05, 2002 at 11:55:00:In Reply to: best way to share data between small and C posted byHan Cicimen on March 05, 2002 at 08:06:13:
: 1) As far as I understand the Small is optimised for 32 bit platforms. When ý check the amx.c I noticed malloc used which limits the data and program size to 64K limit.
The AMX code (AMX.C) does not use malloc() specifically to avoid such limitations. There are a few native functions (in AMXCORE.C and AMXCONS.C) that call malloc(), but only for strings (so you would be limited to 64K characters in a string). The "example" program SRUN.C also uses malloc(), to load the entire program in. This, you can conveniently change into farmalloc().
If the memory block for your compiled script exceeds 64K, you should compile the abstract machine in "huge" memory model. The AMX.C source does not handle any segment:offset complexities.
: 2) In my new application I have to transfer data between native C to Small. There are lots of data and I plan to simplify the system for the script programmer and I plan to use one big array in native C:
A Small script cannot directly access data outside its abstract machine. If a script needs to read/write some byte that is stored in the host application, it can only do this by calling a native function.
For example, if you implement two native functions, peek() and poke(), the Small script can use these functions to read and write bytes (or cells) into the big array.
Thiader
[313] error report : about goto.
Posted By chop on March 07, 2002 at 00:53:34:Hi.
In first, I want to say thank you for 1.8.3 bug fix, against my report.
I encountered the probrem below.
main()
{
{
goto GOTO_TEST;
}
for( new i=0
[314] Dynamic allocation between scopes
Posted By Gilad Novik on March 07, 2002 at 05:00:17:Hey,
I am using small as an event handler for my application (using public function)
I need to allocate a global dynamic array from a function. Here is a sample in C.
int *pArray;
int nSize;
void Event1(int nInput)
{
pArray=new int[nSize=nInput];
}
void Event2()
{
for (int i=0;i<nSize;i++)
cout<<pArray[i];
}
Is there a way to do this without the help of native function?
I know I can create a native which would allocate an array, but I want to this from small, not by adding additional function.
Gilad
[315] Sorry, here is the updated sample
Posted By Gilad Novik on March 07, 2002 at 05:03:32:In Reply to: Dynamic allocation between scopes posted by Gilad Novik on March 07, 2002 at 05:00:17:
int *pArray;
int nSize;
void Event1(int nInput)
{
pArray=new int[nSize=nInput];
}
void Event2()
{
for (int i=0;i<nSize;i++)
cout<<pArray[i];
}
[316] How can i pass float values to the abstract machine ?
Posted By Nicolas Sakschewski on March 08, 2002 at 05:51:08:
I've C++ programm witch works with float values. This float values must be passed to the abstract machine, witch send the values to a small script. Witch functions i've to call to pass float values to the abstract machine (and with witch parameters) ?
[317] Re: error report : about goto.
Posted By Thiadmer Riemersma on March 08, 2002 at 10:43:41:In Reply to: error report : about goto. posted bychop on March 07, 2002 at 00:53:34:
Thank you for your very precise report. This is a bug in the "for" loop, which has the nasty habbit of deleting any label that is declared at a lower scope than the "for" loop itself.
I have just fixed this. If you cannot wait for the next release (it may take a few weeks):
In file SC1.c, function dofor(), at line 3140, it currently reads:
delete_symbols(&loctab,ncmp,TRUE,TRUE);
Change the third parameter into FALSE, so it becomes:
delete_symbols(&loctab,ncmp,FALSE,TRUE);
Thiadmer
[318] Re: How can i pass float values to the abstract machine ?
Posted By Thiadmer Riemersma on March 11, 2002 at 03:49:00:In Reply to: How can i pass float values to the abstract machine ? posted byNicolas Sakschewski on March 08, 2002 at 05:51:08:
You can pass float values directly in amx_Exec(), but you must type-cast them to the "cell" first. The problem is, when you pass a "float" type to a function that accepts a variable length argument list, C/C++ converts each "float" to "double". However, Small only supports "float", not "double".
The typecast from "float" to "cell" is tricky also: C/C++ converts the bit pattern during the cast, which scrambles the value in our case. To cast a float to a cell, I suggest a function like the following:
static cell ConvertFloatToCell(float fValue)
{
float *pFloat;
cell fCell;// Get a pointer to the cell that is a float pointer.
pFloat = (float *)((void *)&fCell);// Now put the float value into the cell.
*pFloat = fValue;// Return the cell that contains the float
return fCell;
}
I took this function from FLOAT.CPP in the Small toolkit. It is possible to rewrite this function to a single line expression, something like:
static cell ConvertFloatToCell(float fValue)
{
return * ((cell*) &fValue);
}
Thiadmer
[319] Problems with public variables
Posted By Nicolas Sakschewski on March 12, 2002 at 10:58:42:
The function "amx_FindPubVar" finds only the public decimal and float variables of a small script.
How can i find the public string variables ?
[320] Re: Dynamic allocation between scopes
Posted By Thiadmer Riemersma on March 12, 2002 at 11:59:43:In Reply to: Dynamic allocation between scopes posted byGilad Novik on March 07, 2002 at 05:00:17:
: I need to allocate a global dynamic array from a function. Here is a sample in C.
This currently requires the help of native functions. You cannot allocate dynamic memory in Small. This is on my "wish list", but I am not close to implementing it right now.
Thiadmer
[321] Re: Problems with public variables
Posted By Thiadmer Riemersma on March 12, 2002 at 12:06:35:In Reply to: Problems with public variables posted byNicolas Sakschewski on March 12, 2002 at 10:58:42:
: The function "amx_FindPubVar" finds only the public decimal and float variables of a small script. How can i find the public string variables ?
Strings are arrays. When you work with arrays, you need to know its starting address and its dimensions. When I implemented public variables, I pushed the complexities of (multi-dimensional) public arrays forward. I will see whether I can add public arrays soon.
Thiadmer
[322] Compiling Srun with JIT
Posted By Brad Fidler on March 12, 2002 at 13:14:21:Does anyone have tips on getting srun to compile with JIT?
When I try to compile with BCC as described in the smallguide with
bcc32 -DJIT -Tm2 srun.c amx.c amxcore.c amxcons.c jits.asm
it complains that it does not know what VirtualProtect or PAGE_EXECUTE_READWRITE are from amx.c
These are defined in winbase.h so I put a include in amx.c and recompiled.
It really freaks out with 100+ errors like undefined indentifier DWORD, blah blah blah in winbase.h
Tried to compile with MSVC, exact same problems.
Instead of including winbase.h I included win.h from LCCWin32 which has all these prototypes.
(I had to fix up some lines that refer to LONG LONG as MSVC and BCC don't know what that is)
It compiles OK, but linking dies with 4 errors,
undefined reference to __assertfail in srun, amx, amxcore and amxcons.obj
(I think it was __assertfail or __assertfailed, can't remember right now)
I did a search through all the files in the AMX dir but can't find any reference to __assertfail anywhere.
Am I missing something?
Any help would be appreciated.
Thanks.
[323] Re: Compiling Srun with JIT
Posted By Thiadmer Riemersma on March 17, 2002 at 09:43:23:In Reply to: Compiling Srun with JIT posted byBrad Fidler on March 12, 2002 at 13:14:21:
: When I try to compile with BCC as described in the smallguide with
: bcc32 -DJIT -Tm2 srun.c amx.c amxcore.c amxcons.c jits.asm
: it complains that it does not know what VirtualProtect or PAGE_EXECUTE_READWRITE are from amx.c
I broke something in a recent update: originally, OSDEFS.H included WINDOWS.H, which is needed for the JIT support. This gave problems on some non-Windows platforms, such as the XBox SDK, so I removed it.
To fix this, add the following three lines to AMX.C (at the end of the series of #include lines):
#if defined JIT
#include <windows.h>
#endif
Thiadmer
[324] SmallC and data alignement
Posted By Stephane Denis on March 22, 2002 at 07:40:28:
In previous e-mail with Thiadmer, I have suggested some suggested to improve the data alignement support of the smallC engine.
In fact, actually the current implementation could not run on machine where 32bit integers needs to be aligned (like MIPS or PowerPC). Especially in the header of the AMX file.
I've proposed a fix and seemed to works.
Other problems, is the 'segment' aligment. I mean if you declare globally or statically some array (for example an array of float defining a vector) and using native function that requires that theses array needs to be aligned in a 64bit or even a 128bit boundary.
For example. let's figure a smallC script using some mathematic functions for animations or 3d but using some native functions using SSE2 instructions. it should be fine either in the compilation or using a #pragma align 32 or 64 or 128 to align the beginning of the data segment to 32 or 64bit. I've done some modifications and seems to works.
Still the stack alignement data. in fact when using the amx_GetAddr in the 'native' side, we must be sure that address is 64bit or 128bit aligned.
So actually, i'm waiting that this last feature is performed.
Doing this will also ensure that SmallC would be ready for 64bit environment where data pointers needs to be 64bit aligned.
[325] Lua Small?
Posted By David Simon on March 22, 2002 at 20:37:23:Have you looked at the Lua language? It's at www.lua.org. It seems to have the same primary goals as Small (speed, minimalism) though it uses an interesting syntax/implementation that I can only describe as a crossbreed between BASIC and Scheme (no, really :-D). Anyways, since I'm making an app that involves such scripting intimately (specifically, it needs to either interpret or compile in a cross platform way, and it needs to be very fast, since a lot of scripts will be ran repeatedly) in my RPG engine project, Buzz Buzz.
Anyways, I was wondering if you could describe what benefits Small and Lua have on each other, being in the same niche. Thanks!
[326] Re: DLL's?
Posted By robert harris on March 25, 2002 at 07:30:53:In Reply to: Re: DLL's? posted byThiadmer Riemersma on April 01, 2001 at 08:29:55:
: : I'm wondering if it's possible to link to C++ dll files and use their functionality in the Small language, if so how? Thanks in advance.
: I have included a general purpose DLL call function in the DLL versions of the abstract machine; the function is called "calldll()". It is not very well documented, and the corresponding loaddll() and freedll() functions are still missing. I made the function mostly because I needed a quick function to call any Win32 API function and the USER, KERNEL and GDI modules are already loaded for a Win32 "windowed" application.
: If you need to call specific native functions from a specific DLL, the DLL just needs to register its functions to the AMX. The readme.txt file has some information on this.
: Thiadmer
[327] Re: Lua Small?
Posted By Michael Zöller on March 25, 2002 at 07:44:40:In Reply to: Lua Small? posted byDavid Simon on March 22, 2002 at 20:37:23:
I'm not really into this thing yet, but as you want to write a game engine you certainly want to be able to pause your scripts without pausing your entire game (eg main loop).
small has this nice "sleep" functionality that enables you to put a script on hold and resume execution later on. this way you could set a host abpplication varibale to the msecs you want the script to pause, have this var caounted down by some time routines of yours and resume the script once it's at zero.
suggestions, ideas anyone ??
[328] Mailing list
Posted By Gilad Novik on March 26, 2002 at 08:02:39:How about adding a mailing to your site?
This way you can inform small users regarding updates/modifications
[329] Re: Lua Small?
Posted By Thiadmer Riemersma on March 26, 2002 at 10:07:22:In Reply to: Lua Small? posted byDavid Simon on March 22, 2002 at 20:37:23:
I found back a list of features that I wanted and several languages that I was evaluating (this was before I started on Small). Below you will find some loose comments based on these notes. Note that at the time I needed to decide what to do or take, Lua was at version 2.2 (if memory serves).
1. When I made my decision as to what scripting language to use, the Lua interpreter was not yet re-entrant (so you could not run different scripts in separate threads). This was fixed in version 3.1. So this is perhaps just a matter of bad timing (on my side).
2. I needed integer arithmetic. Lua does all arithmetic in floating point. Floating point operations can lead to tiny errors, which in turn can accumulate to bigger errors. For the purposes that I had in mind (calculating paths for animations) I could not afford off-by-one errors; I needed the absolute precision of integer arithmetic. (Small supports fixed point and floating point arithmetic via user defined operators.)
3. I wanted a faster scripting language than Lua. That said, a few benchmarks show that Lua is not much slower than Small in some contexts (especially recursive function calling is equally fast in Lua as in Small). See also message 308.
4. It is a matter of preferences: Lua's authors say a scripting language needs good data structuring support but that debugging/error checking support is not essential. I think quite the opposite: for me, error checking, both static and dynamic, is very important, because many users of scripting languages are not always full time programmers. Data modeling is relatively unimportant for me; an analysis showed that most scripts manipulate "application objects" through handles or names (strings). A script accesses an object (say, a cell in a spreadsheet, or a sprite in an animation toolkit) by calling a native function, passing in a handle, name or other specification of the object.
Perhaps it is just that Lua is more elegant, while Small is more pragmatic. Lua has "reflexive facilities", but Small has symbolic constants; Lua's expressions and functions can have multiple values (so you can swap two variables in one line without needing an intermediate variable), but Small's support for pass-by-reference arguments achieve the same thing in typical situations. With Small's support for local, global and file scopes, as well as static locals, I feel that Small is better suited to write large scripts than Lua.
Thiadmer
[330] Re: Mailing list
Posted By Thiadmer Riemersma on March 26, 2002 at 10:10:15:In Reply to: Mailing list posted byGilad Novik on March 26, 2002 at 08:02:39:
: This way you can inform small users regarding updates/modifications
Good idea. I will try to put this up in the next week.
Thiadmer
[331] Include Files...
Posted By Goldorak on March 26, 2002 at 14:15:21:I need string.inc, admin.inc and adminlib.inc to compile a sma but I don't find them... Can anybody help me?
Thanks
[332] small BNF
Posted By Robert Daniels on March 27, 2002 at 15:54:19:Just wondering if there is a small BNF available somewhere?
-Robert
[333] Re: small BNF
Posted By Thiadmer Riemersma on March 28, 2002 at 04:18:59:In Reply to: small BNF posted byRobert Daniels on March 27, 2002 at 15:54:19:
: Just wondering if there is a small BNF available somewhere?
Sorry, no. I never wrote down a complete grammar. I used partial grammars on various handwritten sheets, but I cannot find them at this time.
Thiadmer
[334] Re: Include Files...
Posted By Thiadmer Riemersma on March 28, 2002 at 04:26:48:In Reply to: Include Files... posted byGoldorak on March 26, 2002 at 14:15:21:
: I need string.inc, admin.inc and adminlib.inc to compile a sma but I don't find them... Can anybody help me?
I had been hoping someone else would step into this, as I know only little about the Adminmod. To the best of my knowledge, the include files are in the "halflife-admin-2.50.26.zip" archive that you can download from www.adminmod.org (see also the link at the end of this message).
Thiadmer
[335] Re: Include Files...
Posted By Florian Zschocke on March 31, 2002 at 11:07:25:In Reply to: Include Files... posted byGoldorak on March 26, 2002 at 14:15:21:
When you download Admin Mod and unpack it, you will find everything related to scripting in the "scripting" directory. The include files are in the "scripting/include" directory. To compile a script for Adminmod simply place it in the "scripting/myscripts" directory. You will find a batch file called 'compile_all.bat' in the Windows version and a shell script called 'compile_all.sh' in th Linux version in the same directory. Simply run this script as it takes care of setting compiler options like the inlcude path. Your compiled script will be placed in the "scripting/mybinaries" directory. For further information have a look at the Scripting Basics section in the Admin Mod manual or ask in the Admin Mod forums.
[336] is there a way to handle file ?
Posted By YoGi on April 18, 2002 at 11:55:54:
..a lib, or native functions.. such as fopen, opendir, fgets, etc such as in C
[337] Sleep()
Posted By Bryan on April 19, 2002 at 04:24:37:
Was wondering if someone could help me out with any function that could emulate sleep(#secs). Does SMALL have a straightforward way of doing this?
[338] Passing multi-dimensional arrays to a small function?
Posted By Ravenous Bugblatter Beast on April 28, 2002 at 15:20:18:I am attempting to pass an array of strings to a small function, without much sucesss:
#define L_COUNT = 4
new a[L_COUNT][] = { "English", "French","German", "Spanish" };
How do I write a function that accepts the variable a as an argument?
function func(b[L_COUNT][]) {
}
x= func(a);
generates error 35 - type mismatch at compile time
function func(b[L_COUNT]) {
compiles OK, but inside the function b[0] returns garbage, not "English". I have also tried:
new a[L_COUNT][10] = { "English", "French","German", "Spanish" };
I am using the version of small embedded into half-life adminmod.
[339] Precompiled headers
Posted By Maurizio Ferraris on April 30, 2002 at 08:26:21:
Is there an easy way to speed up the compiler with some sort of precompiled headers.
I have a couple of large, automatically generated include files full of #define, that I include even in simple scripts.
The compilation time is thus very long.
These large includes don't change very often, while the scripts do.
I understand that to accomplish this means probably not an easy change to the compiler. Anyway ...
I can have a look at it if given some suggestion where to look first. I believe that after the first pass into the include files, we need to save the symbol table to a file, and if the file already exist simply skip the first pass through the includes and just reload the file.
[340] Re: is there a way to handle file ?
Posted By Thiadmer Riemersma on May 06, 2002 at 08:23:52:In Reply to: is there a way to handle file ? posted byYoGi on April 18, 2002 at 11:55:54:
: ..a lib, or native functions.. such as fopen, opendir, fgets, etc such as in C
I have seen file access functions (in a native library) in Adminmod. You may want to look at the source code of that tool. See http://www.adminmod.org/
Thiadmer
[341] Re: Sleep()
Posted By Thiadmer Riemersma on May 06, 2002 at 08:34:41:In Reply to: Sleep() posted byBryan on April 19, 2002 at 04:24:37:
: Was wondering if someone could help me out with any function that could emulate sleep(#secs). Does SMALL have a straightforward way of doing this?
The "sleep" instruction can probably help you here, but it needs support of the host program. The standard sample program SRUN.C says:
err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN, 0);
while (err == AMX_ERR_SLEEP)
err = amx_Exec(&amx, &ret, AMX_EXEC_CONT, 0);
Instead of just restarting the same executable immediately again in the "while" loop, you could use this to select another "amx" to run next.
The variable "ret" holds the parameter of the "sleep" instruction, which you could use to specify a sleep count in seconds.
Thiadmer
[342] Re: Precompiled headers
Posted By Thiadmer Riemersma on May 06, 2002 at 08:40:49:In Reply to: Precompiled headers posted byMaurizio Ferraris on April 30, 2002 at 08:26:21:
: Is there an easy way to speed up the compiler with some sort of precompiled headers.
I will add this to my "to do" list. I do not have any idea when this will be implemented, however. It might take some time.
Thiadmer
[343] fdiv returns negative result with 2 positive operands
Posted By David Liersch on May 09, 2002 at 12:06:33:Hi, I use SMALL while writing a plugin (PTB) for AdminMod (adminmod.org). I have no idea, if floating point arithmetic would work, but I didn't find any include files in the AdminMod distribution, which handle float division or the like.
That's why I use fixed numbers. There actually is an include called fixed.inc, that defines the fmul and fdiv functions. But it regularly happens to me, that fdiv returns negative numbers when dividing 2 positive operands. All my numbers are positive, so I really wondered when first seeing this.
Is there any limitation on fixed numbers, that I have to stick to?
Any suggestions are very welcome, as this is really a pain ...
Regards, David
[344] get current time
Posted By angrysand on May 09, 2002 at 18:07:56:Any way to get the current time? I'm new to small and am having some trouble writing a small script that runs with admin_mod for hl.
Basically, it has a function systemtime() that gets current seconds from epoch... but I need to know what the current hour/minutes is. the script is trying to print "The server's current time is %" and passing it systemtime, but it either prints gibberish or the actual huge number... I am looking for something more like "5:30 AM"
Can anyone help or point me in the right direction?
[345] Re: fdiv returns negative result with 2 positive operands
Posted By Thiadmer Riemersma on May 10, 2002 at 12:55:11:In Reply to: fdiv returns negative result with 2 positive operands posted byDavid Liersch on May 09, 2002 at 12:06:33:
: [...] I have no idea, if floating point arithmetic would work, but I didn't find any include files in the AdminMod distribution, which handle float division or the like.
I have not verified whether Adminmod supports floating point arithmetic, but it appears unlikely. Small depends on support of the host program for floating point and fixed point support. In general, a host program supports either fixed point or floating point, but not both.
: [...] There actually is an include called fixed.inc, that defines the fmul and fdiv functions. But it regularly happens to me, that fdiv returns negative numbers when dividing 2 positive operands. All my numbers are positive, so I really wondered when first seeing this.
Looks like a bug. I do not know (right now) how the fixed point arithmetic is implemented. The include file that Small comes with has a divisor of 1000. This allows a value range from -2147483 to +2147483 with three decimals. If you stay within that range, either there is a bug if fdiv, or Adminmod uses a different definition.
Actually, I think there is a bug somewhere. Could you give me a specific example (two positive values fro which fdiv() gives a negative result)? I will then look into it.
Thiadmer
[346] On Compile Error String admin and adminlib failed
Posted By agathis on May 11, 2002 at 21:45:04:
Hi i have a problem with a *.sma compiling he doesnt found follow datas
string.inc
admin.inc
adminlib.inc
its failed can anyone send me 3 files via e-mail please
thearea@magenet.de
[347] Re: On Compile Error String admin and adminlib failed
Posted By Florian Zschocke on May 12, 2002 at 05:16:42:In Reply to: On Compile Error String admin and adminlib failed posted byagathis on May 11, 2002 at 21:45:04:
: Hi i have a problem with a *.sma compiling he doesnt found follow datas
: string.inc
: admin.inc
: adminlib.inc
Questions regarding coding for Admin Mod are best asked at the Admin Mod forums under http://www.ozforums.com/forumdisplay.php?forumid=62
The three files you mention come with Admin Mod which you can download from http://www.adminmod.org/index.php?go=downloads
[348] Re: get current time
Posted By Florian Zschocke on May 12, 2002 at 05:27:36:In Reply to: get current time posted byangrysand on May 09, 2002 at 18:07:56:
Questions regarding coding for Admin Mod are best asked in the Admin Mod forum under http://www.ozforums.com/forumdisplay.php?forumid=62.
In your case you should use servertime() instead of systemtime(). Prototype:
servertime( sTimeString[], iMaxLen, sFormat[] = "none" )
The function will return the seconds from epoch and in addition it can place a formatted string in sTimeString[]. The format can be controlled by a format stringed passed via sFormat[]. The format string follows the strftime() (man strftime) format. If "none" is used a string similar to the one returned by asctime() (man asctime) is returned.
To get "5:30 AM" you would use the following:
new timestr[10];
servertime( timestr, 10, "%I:%M %p" );
[349] Possible to use Small as a kind of 'time sharing' interpreter?
Posted By Frank Siegert on May 12, 2002 at 23:36:11:I am looking for a interpreted script language for my upcoming game Project 2501, where small tanks battle each other in 3D (alike BZ Flag but with much more gimmicks and graphical eye candy). Right now robots are coded in C++ and linked to the game upon compile time. Now Small looks like a nice way to add "robot" tanks to the game where the user can supply the "brain" in form of a script (thus making it a kind of 3d coreware). Now several of these "brains" could be active in one client, each for every robot tank on the move in the world. To handle things I could either multithread the single brains, however synchronizing with the main thread would need some work or - and that brings me back to my question - call out the 'brain' instance of Small and ask the interpreter only to give each script only a few ms runtime before returning control to the main thread (and 'save' the state of the interpreter to make it possible to call it again the next time). Is this possible in the current implementation (maybe with the help of the debug interface, I would prefer something that does not give too much speed penality) or can be build into with much ago? Or is this approach basically flawed and I should go for the threaded solution?
Thanks for any comments!
Frank
[350] Re: Possible to use Small as a kind of 'time sharing' interpreter?
Posted By Thiadmer Riemersma on May 14, 2002 at 03:44:32:In Reply to: Possible to use Small as a kind of 'time sharing' interpreter? posted byFrank Siegert on May 12, 2002 at 23:36:11:
There are basically two approaches: cooperative multi-threading using a feature of the Small language and time-sliced multi-threading using the OS and no help from Small at all. There may be a third "middle-ground" approach that uses the debugger interface.
Cooperative multi-threading means that the script programmer programs a "yield" instruction at various positions in his code. Essentially, this is how "multi-tasking" worked in Windows 3.x (and before); GetMessage() and PeekMessage() do an implicit yield. For Small, the "yield" is done with the "sleep" instruction.
The drawback is that one "badly" written script may harm the responsiveness and the "fluidity" of the complete system.
With time-sliced threads that the operating system provides, every script runs in its own thread. The threads are independent.
The debugger interface can, at best, provide a kind of "source line-sliced" multi-threading. You get an event for every statement on a new source line that is about to run. A statement may take just very little time, or it may take a lot of time when native function calls are involved. So this is a compromise: it is an automatic solution, and therefore arguably a better solution then requiring the script programmer to insert "sleep" instructions at critical locations. On the other hand, the overhead of the debugger interface may be bigger than the thread switching operation by the OS (I haven't timed this). And before I forget it, the current implementation of the debugger was designed to only continue the same abstract machine than the one it interrupted. I am not sure whether switching abstract machines on a DBG_LINE event works or fails at this moment (and if it fails, it is easy to fix), but it requires attention.
Thiadmer
[351] Floating point *serious* bug
Posted By Stephane Denis on May 14, 2002 at 09:33:11:I think the floating point parsing is totally wrong
Try this code
// BEGIN HOUSTON.SMA
#include <console>
#pragma pack 1 // Packed Strings
#pragma dynamic 64 // Stack / Heap Size
#pragma rational float
main()
{
new float: sum = 1.0 + 2.0 + 4.0;
if (sum!=7.0)
{
printf("Houston, we have a problem 1.0 + 2.0 + 4.0 = %f", sum);
}
else
printf("Ok");
}
// END HOUSTON.SMARunning with SRUN.EXE, version 1.8.3, I have this output
Houston, we have a problem 1.0 + 2.0 + 4.0 = -2.000000
Run time: 0.00 seconds
Any comments ???
[352] Re: Floating point *serious* bug
Posted By Stephane Denis on May 14, 2002 at 09:45:50:In Reply to: Floating point *serious* bug posted byStephane Denis on May 14, 2002 at 09:33:11:
: I think the floating point parsing is totally wrong
: Try this code
: // BEGIN HOUSTON.SMA
Hum
#include <float>
was missing;
But, oddly, the compiler did not produces any warning or errors ...
This should be fixed;
[353] * Bug #define and floating point *
Posted By Stephane Denis on May 14, 2002 at 10:30:40:There is a problem when using #define and floating point
<< START HOUSTON.SMA >>
#include <console>
#include <float> // now it's here
#pragma pack 1 // Packed Strings
#pragma dynamic 64 // Stack / Heap Size
#pragma rational float
#define VALUE 800.0
main()
{
new float: fDst = 2480.012;
if (fDst < VALUE)
{
printf("Houston, we have a problem %f < %f", fDst, VALUE);
}
else
printf("Ok");
}
<< END HOUSTON.SMA >>The output:
Houston, we have a problem 2480.011963 < 800.000000
Run time: 0.00 seconds
Any comments (now there #include <float>
Best;
[354] * Bug #define and floating point *
Posted By Stephane Denis on May 14, 2002 at 10:31:04:There is a problem when using #define and floating point
<< START HOUSTON.SMA >>
#include <console>
#include <float> // now it's here
#pragma pack 1 // Packed Strings
#pragma dynamic 64 // Stack / Heap Size
#pragma rational float
#define VALUE 800.0
main()
{
new float: fDst = 2480.012;
if (fDst < VALUE)
{
printf("Houston, we have a problem %f < %f", fDst, VALUE);
}
else
printf("Ok");
}
<< END HOUSTON.SMA >>
The output:
Houston, we have a problem 2480.011963 < 800.000000
Run time: 0.00 seconds
Any comments (now there #include <float>
Best;
[355] Re: * Bug #define and floating point *
Posted By Stephane Denis on May 14, 2002 at 11:13:32:In Reply to: * Bug #define and floating point * posted byStephane Denis on May 14, 2002 at 10:31:04:
The forum seems to not display correctly mail
: There is a problem when using #define and floating point
: I re-send the mail
: << START HOUSTON.SMA >>
: #include "console.inc"
: #include "float.inc"
: #pragma pack 1 // Packed Strings
: #pragma dynamic 64 // Stack / Heap Size
: #pragma rational float
: #define VALUE 800.0
: main()
: {
:
: new float: fDst = 2480.012;
: if (fDst < VALUE)
: {
: printf("Houston, we have a problem %f < %f", fDst, VALUE);
: }
: else
: printf("Ok");
: }
: << END HOUSTON.SMA >>
: The output:
: Houston, we have a problem 2480.011963 < 800.000000
: Run time: 0.00 seconds
: Any comments (now there #include <float>
: Best;
[356] Crash when wrongly using if / else
Posted By Stephane Denis on May 15, 2002 at 06:57:00:Try this code and get an assert in sc2.c, line 1213
Maybe an error message like error: parse error before `{' should be fine:
main()
{
if ( 1 == 2)
{
}
else if
{
}
else
{
}
}
[357] The use of => in arguments
Posted By SR71Goku on May 18, 2002 at 16:47:32:
I've noticed that the compiler will not let you use => in arguments but it will allow >=. Others and I have noticed this and it can often be an annotnace when scripting. I'm just posting this to make you aware of this problematic bug.
[358] The use of => in arguments
Posted By SR71Goku on May 18, 2002 at 17:01:09:
I've noticed that the compiler will not let you use => in arguments but it will allow >=. Others and I have noticed this and it can often be an annotnace when scripting. I'm just posting this to make you aware of this problematic bug.
[359] The use of => in arguments
Posted By SR71Goku on May 18, 2002 at 17:01:27:
I've noticed that the compiler will not let you use => in arguments but it will allow >=. Others and I have noticed this and it can often be an annotnace when scripting. I'm just posting this to make you aware of this problematic bug.
[360] The use of => in arguments
Posted By SR71Goku on May 18, 2002 at 17:03:21:
I've noticed that the compiler will not let you use => in arguments but it will allow >=. Others and I have noticed this and it can often be an annotnace when scripting. I'm just posting this to make you aware of this problematic bug.
[361] Re: The use of => in arguments
Posted By SR71Goku on May 18, 2002 at 20:20:03:In Reply to: The use of => in arguments posted bySR71Goku on May 18, 2002 at 17:03:21:
Sorry about posting so many times. When I didn't see it posted right away, I tried again.
[362] Bang goes the JIT. Bug report.
Posted By Dan Andersson on May 21, 2002 at 19:29:34:This is a pretty minimal program that runs OK under srun 1.8.4 for win32 but triggers a runtime error under srun_jit:
#include <console>
#include <core>
main()
{
printf("%d", swapchars(0))
}
The output:
C:\WINDOWS\Skrivbord\lang\small\small new\smallwin32>sc inv6
Small compiler 1.8.4 Copyright (c) 1997-2002, ITB CompuPhase
Done.
C:\WINDOWS\Skrivbord\lang\small\small new\smallwin32>srun inv6.amx
0
Run time: 0.00 seconds
C:\WINDOWS\Skrivbord\lang\small\small new\smallwin32>srun_jit inv6.amx
Run time error 19 on line 7
Run time: 0.00 seconds
C:\WINDOWS\Skrivbord\lang\small\small new\smallwin32>
Thought you would want to know.
MvH Dan Andersson
[363] Re: The use of => in arguments
Posted By Thiadmer Riemersma on May 23, 2002 at 02:21:08:In Reply to: The use of => in arguments posted bySR71Goku on May 18, 2002 at 17:03:21:
: I've noticed that the compiler will not let you use => in arguments but it will allow >=.
This is by design. Small does not set the "=>" operator to mean the same thing as ">=", it really insists that you write ">=".
Thiadmer
[364] Re: Floating point *serious* bug
Posted By Thiadmer Riemersma on May 23, 2002 at 02:39:58:In Reply to: Floating point *serious* bug posted byStephane Denis on May 14, 2002 at 09:33:11:
In the code, you have
: #pragma rational float
but you do not define any user-defined operators for the "float" tag. As a result, Small will use integer addition if you add 1.0 and 2.0 (instead of calling the user-defined operator to do floating point addition).
I suggest that you always put the "#pragma rational ..." directive in a header file that also defines the appropriate user-defined operators (the "float.inc" and "fixed.inc" files that come with the toolkit already contains it). In you program, you do not set the "#pragma rational ..." directive, but instead include one of these include files. The advantage is that if you forget to include the header file now, the compiler will complain when it encounters rational number literals.
Thiadmer
: main()
: {
:
: new float: sum = 1.0 + 2.0 + 4.0;
: if (sum!=7.0)
: {
: printf("Houston, we have a problem 1.0 + 2.0 + 4.0 = %f", sum);
: }
: else
: printf("Ok");
: }
: // END HOUSTON.SMA
:
: Running with SRUN.EXE, version 1.8.3, I have this output
: Houston, we have a problem 1.0 + 2.0 + 4.0 = -2.000000
: Run time: 0.00 seconds
:
: Any comments ???
[365] Re: Floating point *serious* bug
Posted By Thiadmer Riemersma on May 23, 2002 at 02:43:56:In Reply to: Re: Floating point *serious* bug posted byStephane Denis on May 14, 2002 at 09:45:50:
: #include <float>
: was missing;
: But, oddly, the compiler did not produces any warning or errors ...
: This should be fixed;
The Small compiler knows very little about floating point arithmetic. In fact, it only knows how to encode floating point literals. I think that I can build a special case in the compiler that warns when you do an integer operation on a floating point value.
Thiadmer
[366] Re: * Bug #define and floating point *
Posted By Thiadmer Riemersma on May 23, 2002 at 03:02:18:In Reply to: * Bug #define and floating point * posted byStephane Denis on May 14, 2002 at 10:30:40:
You can get the program working correctly if you replace
: #define VALUE 800.0
by
: const float: VALUE = 800.0;
I agree that you uncovered a bug in the compiler, or perhaps two. Currently, the #define directive cannot create "tagged" constants and it also isn't text substitution as in C/C++. A fix that I want to make is that #define always takes the tag of the right hand expression for the newly defined constant.
The second bug is that the compiler is much too forgiving when you omit the "float:" tags. For example, if you would replace
: #define VALUE 800.0
by
: const VALUE = 800.0;
the program would compile without warnings and produce an incorrect result.
Thiadmer
[367] Re: * Bug #define and floating point *
Posted By Thiadmer Riemersma on May 23, 2002 at 03:07:23:In Reply to: Re: * Bug #define and floating point * posted byStephane Denis on May 14, 2002 at 11:13:32:
: The forum seems to not display correctly mail
There appear to be (or have been) a few anomalies. I have been bitten by this myself too. That said, it may also be the browser that does not see that a page has changed and loads the previous copy from the cache. I click on the "refresh" button a lot when adding messages to the forum.
Thiadmer
[368] Re: * Bug #define and floating point *
Posted By Thiadmer Riemersma on May 23, 2002 at 07:12:30:In Reply to: * Bug #define and floating point * posted byStephane Denis on May 14, 2002 at 10:30:40:
There is a fix for some of these problems alerady: strong tags.
In message #366 (see the link below) I complained that the compiler is much too forgiving when you do something like:
new fDst = 2480.012;
where you really wanted to type:
new float: fDst = 2480.012;
After typing that message, I suddenly remebered "strong tags". If you say:
#pragma rational Float
with an upper case "F", Float: becomes a strong tag, which will not be automatically dropped (or coerced to untagged) when the left side of an assignment is untagged. Floating point literals now also get this strong tag, so they cannot be stored in an untagged variable.
This solves all problems, but creates a new one in the printf() call: printf() will not accept strongly tagged parameters, unless you explicitly untag them. So printf() must be modified from:
printf("Houston, we have a problem %f < %f", fDst, VALUE);
to
printf("Houston, we have a problem %f < %f", _:fDst, _:VALUE);
Hope this helps (and by the way, the floating point include file must be modified for strong tags, replacing "float:" by "Float:" everywhere),
Thiadmer
[369] DLL entry point not found
Posted By Matthaeus Schimmerl on May 28, 2002 at 08:15:10:
I am using Microsoft Developer Studio 6.0.
When i try to build srun-dll.c using the command line shown in the readme.txt file (cl -DAMXAPI=__stdcall srun-dll.c amx32m.lib) compilation is OK but when i try to execute the program on Windows 2000, a MessageBox is displayed, that the program can not be loaded due to a missing entry point.
The exact errormessage is:
srun-dll.exe - Entry Point Not Found
The procedure entry point amx_Init@8 could not be located in the dynamic link library AMX32.dll.
I've found out, that the error must be in the amx32m.lib, because when i use the library i get, when i compile the dll sources with VC6 and use the downloaded dll, the program can be executed.
Does anybody know, if there is a bug in the downloaded amx32m.lib file or if i have to change compiler options?
[370] BUG report : sc makes wrong code.
Posted By chop on May 28, 2002 at 12:56:34:
Hi.
I found minor bug of small compiler.
this program doesn't work propery.
------
#include <core.inc>
#include <console.inc>
main()
{
new a;
for(;;){
new b = random(2);
new c;
if(b) c = 0;
new d = a--;
printf("d = %d, a = %d\n", d, a );
sleep;
}
}
------
but, this one work propery.
------
#include <core.inc>
#include <console.inc>
main()
{
new a;
for(
[371] Re: DLL entry point not found
Posted By PixiGreg on May 28, 2002 at 14:29:52:In Reply to: DLL entry point not found posted byMatthaeus Schimmerl on May 28, 2002 at 08:15:10:
I have the same problem! Exactly the same error!
Running Win2k too, VC++ 6.
Please help us...
[372] Can someone send me jitr.obj or jits.obj ?
Posted By PixiGreg on May 29, 2002 at 11:49:05:Hi!
can someone send me the compiled jitr.asm or jits.asm, at pixigreg@ifrance.com ?
Thanks alot in advance.
I've got MASM but i get an error when trying to compile it:
jits.asm(402) : error A2006: undefined symbol : CODESIZE
thanks.
[373] problem registering native functions
Posted By PixiGreg on May 30, 2002 at 15:54:41:Hi,
I have another problem...
I want to register custom functions from my program as natives. The problem is: if I put the amx_Register() before amx_Init(), i get an access violation, if I put it after, amx_Init() complains about error 19 (ERROR_NOT_FOUND), which is quite logical, since i've not registered any of my functions... However, when I don't use the function in the Small program, the amx_Register() is successful, since amx_Init() doesn't complain. Arrg.
Have I forgotten something?
I'm using the downloadable AMX DLL. Something I don't understand is that I can use the special DLL natives without any problems (such as messagebox()).
Thanks for your help.
[374] Is... Is someone there ??????
Posted By PixiGreg on June 03, 2002 at 12:46:59:In Reply to: problem registering native functions posted byPixiGreg on May 30, 2002 at 15:54:41:
: Hi,
: I have another problem...
: I want to register custom functions from my program as natives. The problem is: if I put the amx_Register() before amx_Init(), i get an access violation, if I put it after, amx_Init() complains about error 19 (ERROR_NOT_FOUND), which is quite logical, since i've not registered any of my functions... However, when I don't use the function in the Small program, the amx_Register() is successful, since amx_Init() doesn't complain. Arrg.
: Have I forgotten something?
: I'm using the downloadable AMX DLL. Something I don't understand is that I can use the special DLL natives without any problems (such as messagebox()).
: Thanks for your help.
-----------------------------
this forum seems to be dead...
Please help me, deads or undeads!
[375] Re: problem registering native functions
Posted By Matthaeus Schimmerl on June 04, 2002 at 11:11:19:In Reply to: problem registering native functions posted byPixiGreg on May 30, 2002 at 15:54:41:
: Hi,
: I have another problem...
: I want to register custom functions from my program as natives. The problem is: if I put the amx_Register() before amx_Init(), i get an access violation, if I put it after, amx_Init() complains about error 19 (ERROR_NOT_FOUND), which is quite logical, since i've not registered any of my functions... However, when I don't use the function in the Small program, the amx_Register() is successful, since amx_Init() doesn't complain. Arrg.
: Have I forgotten something?
: I'm using the downloadable AMX DLL. Something I don't understand is that I can use the special DLL natives without any problems (such as messagebox()).
: Thanks for your help.
after calling amx_Init() and this function returns AMX_ERR_NOTFOUND, you have to register native functions by calling amx_Register() until this function returns AMX_ERR_NONE. Once this function has returned AMX_ERR_NONE, you can call amx_Exec() or amx_Ececv().
Matthäus Schimmerl
[376] Multiple instances of the same code - help
Posted By Greg Denness on June 18, 2002 at 20:08:23:Hello, I use small for a project called Open Zelda, its a kind of RPG where people make their own "quests". Everything in OZ is controlled by a small script, from the player to the menu system, which means that anyone can add anything to the game, its a system that works really well.
My question is this, if I have say 10 enemies on the screen, they would all have their own copies of the same small script. Would it be possible to have them share the same code in memory but each have their own amx structures? this would save so much memory.
So I would want to do this for each .amx file:
fp = fopen(filename,"rb")
fread(&hdr, sizeof hdr, 1, fp);
program = malloc((int)hdr.stp))
rewind(fp);
fread(program, 1, (int)hdr.size, fp);
fclose(fp);
And then for each enemy I would want to initialise their amx structures, but just refer to the same copy of the script, not create a new copy of the script in memory each time.
Is this possible at all? if its not then I think it would be a really good feature to add as it would make small a lot more useful.
You can see Open Zelda at:
http://openzelda.armageddongames.com/
If you have a chance get the Quest Designer program as well, there are many small scripts in it.
Thanks
-GD
[377] parsing an int from a string...
Posted By Brad Schulteis on June 21, 2002 at 19:05:11:Is there an easy way to parse an int from a string? such as the java parseInt function? PLEASE help, thanks.
Brad
[378] Re: BUG report : sc makes wrong code.
Posted By Thiadmer Riemersma on June 25, 2002 at 12:06:43:In Reply to: BUG report : sc makes wrong code. posted bychop on May 28, 2002 at 12:56:34:
: new d = a--;
This is a problem in the peephole optimizer of the Small compiler. For the moment, one workaround is to split this declaration into two lines, like:
: new d = a;
: a--;
Alternatively, you can shut off the peephole optimizer with the compiler option -d3. Unfortunately, this also includes full debug information.
I will fix the code generation as soon as possible.
Thiadmer
[379] small with the MC68331 cpu and 16bit ints
Posted By Leopold Faschalek on June 26, 2002 at 07:17:39:I am running small on my embedded 68k system and found a problem with some casts to (int) in the amx.c small bytecode interpreter.
The casts should be removed or replaced with a better type (like cell)
greetings
[380] assertion in expand()
Posted By Leopold Faschalek on June 26, 2002 at 08:17:13:I have one small programm which triggers this assertion, but seems to run correctly. Is there any problem or may i ignore this assertion ?
/* we work from the end of a sequence backwards; the final code in
* a sequence may not have the continuation bit set*/
ASSERT(shift>0 || (code[codesize] & 0x80)==0);
greetings Leopold
[381] Newbie.
Posted By Someone on June 30, 2002 at 22:45:03:
Do you have a guide for a newbie to this? i cant understand any of it.....
[382] Re: Compiling Srun with JIT
Posted By Brad Fidler on July 17, 2002 at 00:51:58:In Reply to: Compiling Srun with JIT posted byBrad Fidler on March 12, 2002 at 13:14:21:
I have absolutely no idea, but I should inform you that my name is also Brad Fidler.
Cheers,
Brad
: Does anyone have tips on getting srun to compile with JIT?
: When I try to compile with BCC as described in the smallguide with
: bcc32 -DJIT -Tm2 srun.c amx.c amxcore.c amxcons.c jits.asm
: it complains that it does not know what VirtualProtect or PAGE_EXECUTE_READWRITE are from amx.c
: These are defined in winbase.h so I put a include in amx.c and recompiled.
: It really freaks out with 100+ errors like undefined indentifier DWORD, blah blah blah in winbase.h
: Tried to compile with MSVC, exact same problems.
: Instead of including winbase.h I included win.h from LCCWin32 which has all these prototypes.
: (I had to fix up some lines that refer to LONG LONG as MSVC and BCC don't know what that is)
: It compiles OK, but linking dies with 4 errors,
: undefined reference to __assertfail in srun, amx, amxcore and amxcons.obj
: (I think it was __assertfail or __assertfailed, can't remember right now)
: I did a search through all the files in the AMX dir but can't find any reference to __assertfail anywhere.
: Am I missing something?
: Any help would be appreciated.
: Thanks.
[383] Time/date mathematics
Posted By Plugin maker on July 23, 2002 at 21:14:27:Situation:
I read this from a file: <Not important String> <Timestamp> <Length of Time>
The Timestamp is defined as: dd-mm-yyyy (european style)
The Length of time is defined as integer minutes.
Is there a way to calculate time?
I need to anwser the question: Is the Lengt of time passed since the timestamp on current time? And if NOT, what is the difference in integer minutes?
Are there any good functions in small that can be used?
FYI: I am NOT using small directly, I am making a plugin for Adminmod which is small based. I could include a file if given one.
Could anyone please give a usefull comment?
[384] symbol name length
Posted By Chris Jones on July 26, 2002 at 20:27:14:We are automatically generating Small script from a tool we wrote, and have begun running into the 19 character limit for symbol names.
I'd like to up the limit to 32. It appears that all I have to do is change the constant sEXPMAX in amx.h to the limit we want and rebuild everything. Is this true, or am I missing something?
Thanks,
Chris
[385] Re: Time/date mathematics
Posted By Florian Zschocke on July 27, 2002 at 06:59:15:In Reply to: Time/date mathematics posted byPlugin maker on July 23, 2002 at 21:14:27:
For info on writing plugins for Admin Mod, you should rather visit the Admin Mod Scripting Forum. Getting an answer there is more likely than here.
As for your question: Admin Mod provides the function systemtime(). This will return the time of the server in Unix Epoch format. That is an integer value with the seconds passed since 00:00:00 UTC, January 1, 1970. You can easily subtract two such timestamps to get the number of seconds passed since the first timestamp was taken.
For further info ask in the Admin Mod forum.
[386] Re: Possible to use Small as a kind of 'time sharing' interpreter?
Posted By Peter Yu on July 31, 2002 at 19:06:27:In Reply to: Re: Possible to use Small as a kind of 'time sharing' interpreter? posted byThiadmer Riemersma on May 14, 2002 at 03:44:32:
Verified that that failed.
But, like you said, pretty easy to fix.
For future reference (for the less programming-inclined among us):
Take the normal amx.c, search for the second "case OP_LINE:"
Change the lines:
if (num!=AMX_ERR_NONE)
ABORT(amx,num);
to:
if (num!=AMX_ERR_NONE)
{
if (num == AMX_ERR_SLEEP)
{
/* store complete status */
amx->frm=frm;
amx->stk=stk;
amx->hea=hea;
amx->pri=pri;
amx->alt=alt;
amx->cip=(cell)((u_char*)cip-code);
amx->reset_stk=reset_stk;
amx->reset_hea=reset_hea;
return AMX_ERR_SLEEP;
}
ABORT(amx,num);
}
This lets the debugger hook "insert a sleep instruction" anywhere in the code when it returns AMX_ERR_SLEEP, but still allows the script to "die" like before otherwise.
This seemed to be the most natural way to me, as there'd be no extra return values to catch when calling amx_Exec().
[387] !!! THIADMER, WHERE ARE YOU !!!
Posted By PixiGreg on August 04, 2002 at 08:39:55:Hi!
Apparently the author has died... PLEASE THIADMER COME BACK TO LIFE!
Many messages stay un-answered on this forum, and you are often the only person able to answer... If you give the feeling the project is dead, people will give up bugging with Small and turn to other languages where community is more active (such as LUA, what I've done in fact). But SMALL IS THE BEST LANGUAGE, it has a huge potential, so PLEASE DON'T GIVE UP this excellent project!
[388] convert .amx to .sma ?
Posted By Busfahrer on August 04, 2002 at 16:06:16:
Is there any way to convert amx back to sma ???
[389] Re: convert .amx to .sma ?
Posted By Peter Yu on August 05, 2002 at 11:20:48:In Reply to: convert .amx to .sma ? posted byBusfahrer on August 04, 2002 at 16:06:16:
: Is there any way to convert amx back to sma ???
Yes, though it'd not be very simple, since the bytecode format is more or less "assembly language" for the virtual machine. But, by translating that back from binary to "assembly source" form, you can sorta figure it out.
If you'd like to write a program that does that, you can use Appendex D and E in the Implementer's Guide for reference.
[390] Re: !!! THIADMER, WHERE ARE YOU !!!
Posted By yasu on August 06, 2002 at 22:46:46:In Reply to: !!! THIADMER, WHERE ARE YOU !!! posted byPixiGreg on August 04, 2002 at 08:39:55:
EXACTLY my thoughts... :-(
[391] some errors
Posted By LGBR on August 06, 2002 at 23:25:36:
http://12.230.34.40/errors.txt
http://12.230.34.40/plugin_lgbr_money.sma
help?
[392] Re: !!! THIADMER, WHERE ARE YOU !!!
Posted By PixiGreg on August 07, 2002 at 04:39:06:In Reply to: Re: !!! THIADMER, WHERE ARE YOU !!! posted byyasu on August 06, 2002 at 22:46:46:
: EXACTLY my thoughts... :-(
He doesn't even reply emails...
_____________
/ \
| THIADMER, RIP |
| 19?? - 2002 |
| |
| in memory of |
| a great |
| programmer |
| |
------------------------------
[393] Re: !!! THIADMER, WHERE ARE YOU !!!
Posted By yasu on August 07, 2002 at 21:19:49:In Reply to: Re: !!! THIADMER, WHERE ARE YOU !!! posted byPixiGreg on August 07, 2002 at 04:39:06:
What about setting up a sourceforge account for Small? I'm not a lawyer so I'm not sure of if the current license allows this...
Thiadmer did excellent job with this project, and it would be a great loss to everyone to let it die like this. Besides, even if Thiadmer returns, we cannot have any warranty that one day he won't disappear again (I heard that people start using RealLife(TM) and similar products ;-)
: : EXACTLY my thoughts... :-(
: He doesn't even reply emails...
: _____________
: / \
: | THIADMER, RIP |
: | 19?? - 2002 |
: | |
: | in memory of |
: | a great |
: | programmer |
: | |
: ------------------------------
[394] >>> Need good programmers to keep this project alive at Sourceforge <<<
Posted By PixiGreg on August 08, 2002 at 04:53:06:In Reply to: Re: !!! THIADMER, WHERE ARE YOU !!! posted byyasu on August 07, 2002 at 21:19:49:
: What about setting up a sourceforge account for Small? I'm not a lawyer so I'm not sure of if the current license allows this...
: Thiadmer did excellent job with this project, and it would be a great loss to everyone to let it die like this. Besides, even if Thiadmer returns, we cannot have any warranty that one day he won't disappear again (I heard that people start using RealLife(TM) and similar products ;-)
Yes I was strongly thinking about this. Even if Thiadmer comes back, I think he won't reproach us for having keeping alive the project.
Sourceforge is a good way to continue the project.
For license matter, I've taken a look at the license.txt :
<<
Permission is hereby granted, without written agreement and without paid
license or royalty fees, to use, copy, modify, and distribute this software
and its documentation for any purpose, subject to the following conditions:
1. The above copyright notice and this permission notice shall appear in all
copies or substantial portions of the source code of this software. No
notice or acknowledgement is required in binary distributions of this
software.
2. The origin of this software must not be misrepresented; you may not
claim that you wrote the original software, for example.
3. Modifications of this software that do not originate from ITB CompuPhase
must be explicitly mentioned in a README file or another appropriate
place. Altered copies of this software must not be misrepresented as being
the original software.
4. The name "Small" may and should be used to designate the language, its
compiler and the abstract machine implemented in this software and
described in the Small manual, even if the software is embedded in any
other system, as long as its syntax and semantics remain unchanged.
>>
So, I think there is no problem appropriating the project. We must only mention that we're not the funders of the project. Also the project's name must not be changed.
A problem would be : who will be taking the lead of this project at Sourceforge?
We would need a good staff to federate a programmer community and make the project growing.
The staff leader should be a good programmer.
I'm not a guru programmer (I'm 17 and have a strong experience in Perl, a little bit in assembly, and a correct one in C/C++ and MFC).
So, if you're interested in becoming the project leader, answer this topic!
HELP US KEEPING THIS PROJECT ALIVE !
What about you Yasu, what is your level in C (or C++)?
[395] Re: Can someone send me jitr.obj or jits.obj ?
Posted By Thiadmer Riemersma on August 08, 2002 at 09:47:21:In Reply to: Can someone send me jitr.obj or jits.obj ? posted byPixiGreg on May 29, 2002 at 11:49:05:
The latest release (2.0.0) should now include both JITR.OBJ and JITS.OBJ. Note that JITR is probably not useful for you: it depends on the register calling convention of the Watcom C/C++ compiler. As another note, JITS has currently been tested only with Borland C++ (at least, by me).
Thiadmer
[396] He came back!
Posted By PixiGreg on August 08, 2002 at 09:48:48:In Reply to: >>> Need good programmers to keep this project alive at Sourceforge <<< posted byPixiGreg on August 08, 2002 at 04:53:06:
I've just received this email:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Hello PixiGreg,
Thank you for waking me up. I am well, but mostly out of spare time (haven't
even plucked the banjo for months, and that is my _real_ hobby).
I have just uploaded a new release of the toolkit. It fixes many details
that were brought to my attention since the last release, but I forgot to
take notes at every correction, so I do not know all the changes from the
top of my head. What was important for me was that I finally got the JIT
working again (I kept postponing this); now it has the latest opcodes and it
appears to work correctly.
I will check the forum and see what I can do. The problem is that many
questions need a bit of research before I can give some intelligent sounding
answer. Anyway, I'll do my best.
Bye for now,
Thiadmer
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[397] Re: Multiple instances of the same code - help
Posted By Thiadmer Riemersma on August 08, 2002 at 09:52:05:In Reply to: Multiple instances of the same code - help posted byGreg Denness on June 18, 2002 at 20:08:23:
Version 2.0.0 of Small now has a function for this, amx_Clone().The "implementation guide" is up to date as well, and it covers this function.
To use clones:
1. Load the .AMX file initialize it with amx_Init(), also register all native functions. Use this AMX as a template (i.e. never "amx_Exec()" it).
2. Get the size of the data segment and the stack of the template AMX with the new function amx_MemInfo().
3. Allocate a new memory block with the size of the data segment plus the stack. Then call amx_Clone(). The gives you a new AMX that shares the code with the old AMX but that has a private data segment and a private stack.
4. Make sure that you do not use the JIT. The just-in-time compiler relocates code and data and it assumes that the data segment follows the code segment. This is not true for cloned AMX'es.
5. Do not delete the template AMX before deleting all clones. If you free the memory for the template AMX, you free the code base that all clones use. There is no reference counting implemented.
I hope it works (it has not been very well tested so far) and I hope the description is clear.
Thiadmer
[398] Re: parsing an int from a string...
Posted By Thiadmer Riemersma on August 08, 2002 at 10:03:20:In Reply to: parsing an int from a string... posted by Brad Schulteis on June 21, 2002 at 19:05:11:
The Small language has, by intent, very few predefined functions. The idea is that the application that uses the Small toolkit must provide all functions that make sense for that particular application.
That said, you can make such a function is Small yourself, for example:
isdigit(c)
return '0' <= c <= '9'
atoi(string[])
{
new result
for (new i = 0; isdigit(string[i]); i++)
result = result * 10 + (string[i] - '0')
return result
}
[399] Re: small with the MC68331 cpu and 16bit ints
Posted By Thiadmer Riemersma on August 08, 2002 at 10:20:03:In Reply to: small with the MC68331 cpu and 16bit ints posted byLeopold Faschalek on June 26, 2002 at 07:17:39:
Could you give me an example of such a flawed type cast?
Thanks in advance,
Thiadmer
[400] Re: assertion in expand()
Posted By Thiadmer Riemersma on August 08, 2002 at 10:23:17:In Reply to: assertion in expand() posted byLeopold Faschalek on June 26, 2002 at 08:17:13:
You may probably NOT ignore this problem. Could you send me the program that causes this problem by e-mail?
A work-around (until I fix this), is to use the -C- option on the compiler command line (you can set this option permanently by creating a "sc.cfg" configuration file, see the manual).
Thiadmer
[401] Re: Newbie.
Posted By Thiadmer Riemersma on August 08, 2002 at 10:24:42:In Reply to: Newbie. posted bySomeone on June 30, 2002 at 22:45:03:
The best "newbie" guide that I have is the Small "Language guide", see the link at the bottom of this message.
Thiadmer
[402] Re: symbol name length
Posted By Thiadmer Riemersma on August 08, 2002 at 10:31:39:In Reply to: symbol name length posted byChris Jones on July 26, 2002 at 20:27:14:
It should be sufficient to change the sEXPMAX symbol and recompile everything. Make sure that sNAMEMAX is at least as big as sEXPMAX. The value for sEXPMAX was chosen so that the complete structure had a size that was a multiple of 4 bytes; this helps alignment and it may in turn improve performance. So I would suggest that you use 31 or 35 rather than 32 for sEXPMAX.
By the way, sEXPMAX is in AMX.H, sNAMEMAX is in SC.H. If you are using the AMX DLL ("AMX32.DLL"), get the latest version (releases before 2.0.0 defined their own sEXPMAX instead of including AMX.H).
Thiadmer
[403] Re: convert .amx to .sma ?
Posted By Thiadmer Riemersma on August 08, 2002 at 10:38:51:In Reply to: convert .amx to .sma ? posted byBusfahrer on August 04, 2002 at 16:06:16:
I never made a disassembler. It would be fairly easy to create one though. The function amx_BrowseRelocate() in AMX.C runs through all opcodes to check whether everything is okay and relocate a jump address if needed. All that is required is that you let amx_BrowseRelocate() dump the opcode name plus its parameters as a text string into a file.
That gives you assembler for the abstract machine. From the assembler, you may recognize a few typical constructions: variable declarations are obvious and "for" loops are also recognizable, but recovering the original Small source code is not possible.
Thiadmer
[404] Re: some errors
Posted By Thiadmer Riemersma on August 08, 2002 at 10:42:51:In Reply to: some errors posted byLGBR on August 06, 2002 at 23:25:36:
I have not understood your precise question, but it looks that this is related to AdminMod. For info on writing plugins for Admin Mod, you should rather visit the Admin Mod Scripting Forum; see the link below:
[405] Re: Bang goes the JIT. Bug report.
Posted By Thiadmer Riemersma on August 08, 2002 at 10:44:11:In Reply to: Bang goes the JIT. Bug report. posted byDan Andersson on May 21, 2002 at 19:29:34:
The JIT is up to date in release 2.0.0.
[406] Something I still don't understand....
Posted By PixiGreg on August 09, 2002 at 09:30:24:
I compile this:
-----------------------------
#include "include/console.inc"
main()
{
printf("Hi from printf!");
}
----------------------------
I run it with srun.exe:
-----------------------------
Hi from printf!
Run time: 0.00 seconds
------------------------------
I run it with srun_jit.exe:
------------------------------
The instruction at 0x00408b90 referenced memory at 0x00000008.
The memory could not be written.
-------------------------------
What's wrong?!?
OS: Windows 2000 Professional, CPU: Celeron
[407] Re: He came back!
Posted By yasu on August 10, 2002 at 19:54:41:In Reply to: He came back! posted byPixiGreg on August 08, 2002 at 09:48:48:
Thank you PixiGreg, I'm glad there are people caring about Small. Welcome back Thiadmer, you're the one keeping alive the project and community.
Btw, what is the status of compiling Small with Visual C++ .NET? Anyone tried it yet, or is it working out of the box?
Thanks,
YASU
: I've just received this email:
: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
: Hello PixiGreg,
: Thank you for waking me up. I am well, but mostly out of spare time (haven't
: even plucked the banjo for months, and that is my _real_ hobby).
: I have just uploaded a new release of the toolkit. It fixes many details
: that were brought to my attention since the last release, but I forgot to
: take notes at every correction, so I do not know all the changes from the
: top of my head. What was important for me was that I finally got the JIT
: working again (I kept postponing this); now it has the latest opcodes and it
: appears to work correctly.
: I will check the forum and see what I can do. The problem is that many
: questions need a bit of research before I can give some intelligent sounding
: answer. Anyway, I'll do my best.
: Bye for now,
: Thiadmer
: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[408] Re: Something I still don't understand....
Posted By Thiadmer Riemersma on August 11, 2002 at 08:47:57:In Reply to: Something I still don't understand.... posted byPixiGreg on August 09, 2002 at 09:30:24:
: What's wrong?!?
Very likely there is still a bug in the JIT. I tested a few examples with the JIT on Windows 98; I will test again on Windows 2000.
Thiadmer
[409] Functions
Posted By Willa on August 11, 2002 at 13:42:49:
Anywhere I can get a list of built in functions?
[410] Re: Functions
Posted By Thiadmer Riemersma on August 12, 2002 at 05:13:29:In Reply to: Functions posted byWilla on August 11, 2002 at 13:42:49:
: Anywhere I can get a list of built in functions?
As for the Small language itself, there are no built-in functions. The host application provides all built-ins. I suggest that each host application implements at least the "core" and "console" functions, for which you can find the documentation in the Small "Language guide", pages 65-68.
Thiadmer
[411] Re: Functions
Posted By PixiGreg on August 13, 2002 at 06:12:22:In Reply to: Re: Functions posted byThiadmer Riemersma on August 12, 2002 at 05:13:29:
: : Anywhere I can get a list of built in functions?
: As for the Small language itself, there are no built-in functions. The host applicat