<commit_before>.. _builtin_functions:


==================
Built-in Functions
==================

.. index::
    single: Built-in Functions
    pair: Global Symbols; Built-in Functions


^^^^^^^^^^^^^^
Global Symbols
^^^^^^^^^^^^^^

.. js:function:: array(size,[fill])

create and returns array of a specified size.if the optional parameter fill is specified its
value will be used to fill the new array's slots. If the fill parameter is omitted null is used instead.

.. js:function:: seterrorhandler(func)


sets the runtime error handler

.. js:function:: callee()


returns the currently running closure

.. js:function:: setdebughook(hook_func)


sets the debug hook

.. js:function:: enabledebuginfo(enable)

enable/disable the debug line information generation at compile time. enable != null enables. enable == null disables.

.. js:function:: getroottable()

returns the root table of the VM.

.. js:function:: setroottable(table)

sets the root table of the VM. And returns the previous root table.

.. js:function:: getconsttable()

returns the const table of the VM.

.. js:function:: setconsttable(table)

sets the const table of the VM; returns the previous const table.

.. js:function:: assert(exp)

throws an exception if exp is null

.. js:function:: print(x)

prints x to the standard output

.. js:function:: error(x)

prints x in the standard error output

.. js:function:: compilestring(string,[buffername])

compiles a string containing a squirrel script into a function and returns it::

    local compiledscript=compilestring("::print(\"ciao\")");
    //run the script
    compiledscript();

.. js:function:: collectgarbage()

    runs the garbage collector and returns the number of reference cycles found(and deleted) This function only works on garbage collector builds.

.. js:function:: resurrectunreachable()

runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds.

.. js:function:: type(obj)

return the 'raw' type of an object without invoking the metamethod '_typeof'.

.. js:function:: getstackinfos(level)

returns the stack informations of a given call stack level. returns a table formatted as follow: ::

    {
        func="DoStuff", //function name

        src="test.nut", //source file

        line=10,        //line number

        locals = {      //a table containing the local variables

            a=10,

            testy="I'm a string"
        }
    }

level = 0 is the current function, level = 1 is the caller and so on. If the stack level doesn't exist the function returns null.

.. js:function:: newthread(threadfunc)

creates a new cooperative thread object(coroutine) and returns it

.. js:data:: _versionnumber_

integer values describing the version of VM and compiler. eg. for Squirrel 3.0.1 this value will be 301<commit_msg>fix getstackinfos docs<commit_after>.. _builtin_functions:


==================
Built-in Functions
==================

.. index::
    single: Built-in Functions
    pair: Global Symbols; Built-in Functions


^^^^^^^^^^^^^^
Global Symbols
^^^^^^^^^^^^^^

.. js:function:: array(size,[fill])

create and returns array of a specified size.if the optional parameter fill is specified its
value will be used to fill the new array's slots. If the fill parameter is omitted null is used instead.

.. js:function:: seterrorhandler(func)


sets the runtime error handler

.. js:function:: callee()


returns the currently running closure

.. js:function:: setdebughook(hook_func)


sets the debug hook

.. js:function:: enabledebuginfo(enable)

enable/disable the debug line information generation at compile time. enable != null enables. enable == null disables.

.. js:function:: getroottable()

returns the root table of the VM.

.. js:function:: setroottable(table)

sets the root table of the VM. And returns the previous root table.

.. js:function:: getconsttable()

returns the const table of the VM.

.. js:function:: setconsttable(table)

sets the const table of the VM; returns the previous const table.

.. js:function:: assert(exp)

throws an exception if exp is null

.. js:function:: print(x)

prints x to the standard output

.. js:function:: error(x)

prints x in the standard error output

.. js:function:: compilestring(string,[buffername])

compiles a string containing a squirrel script into a function and returns it::

    local compiledscript=compilestring("::print(\"ciao\")");
    //run the script
    compiledscript();

.. js:function:: collectgarbage()

    runs the garbage collector and returns the number of reference cycles found(and deleted) This function only works on garbage collector builds.

.. js:function:: resurrectunreachable()

runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds.

.. js:function:: type(obj)

return the 'raw' type of an object without invoking the metamethod '_typeof'.

.. js:function:: getstackinfos(level)

returns the stack informations of a given call stack level. returns a table formatted as follow: ::

    {
        func="DoStuff", //function name

        src="test.nut", //source file

        line=10,        //line number

        locals = {      //a table containing the local variables

            a=10,

            testy="I'm a string"
        }
    }

level = 0 is getstackinfos() itself! level = 1 is the current function, level = 2 is the caller of the current function, and so on. If the stack level doesn't exist the function returns null.

.. js:function:: newthread(threadfunc)

creates a new cooperative thread object(coroutine) and returns it

.. js:data:: _versionnumber_

integer values describing the version of VM and compiler. eg. for Squirrel 3.0.1 this value will be 301
{'fraction_non_alphanumeric': 0.10476819006764561, 'fraction_numerical': 0.004124731892426992, 'mean_word_length': 3.7396403440187647, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4886710', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1599, 'n_words': 720}