G.CompileString

From GMod Wiki

Revision as of 15:14, 17 July 2011 by TheFreeman193 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax CompileString( String code, String identifier [, Boolean handleError] )
Where is this used?
Description:
Compiles the string of Lua code as a function and returns it. If there is an error, it will print the error to the console and return nil. If handleError is set to false (it's set to true by default), it will return an error string on failure, instead of nil.
Returns: Function or String or nil
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.CompileString]G.CompileString [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionThis will try to run a string, but fail and display the error.
Used onNewerShared.png
Code
local lua = "print( undefinedtable[3] )"
 
local status, err = pcall( CompileString( lua, "testcode" ) )
print( status, err )
Outputfalse testcode:1: attempt to index global 'undefinedtable' (a nil value)


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox